<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">
<script>
    (function () {
        if ('') {
            if (prompt('请输入文章密码') !== '') {
                alert('密码错误！');
                if (history.length === 1) {
                    location.replace("https://google.com"); // 这里替换成你的首页
                } else {
                    history.back();
                }
            }
        }
    })();
</script>








<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="linux,">










<meta name="description" content="磁盘空间不足12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758df命令查看当前计算器磁盘空闲情况 df -a 从根目录下开始使用du命令查找出空间占用最大的文件  du -sh /*命令一路追查 [root@test-os testus">
<meta name="keywords" content="linux">
<meta property="og:type" content="article">
<meta property="og:title" content="linux 笔记">
<meta property="og:url" content="http://yoursite.com/2019/04/26/linux-笔记/index.html">
<meta property="og:site_name" content="苏生不惑的博客">
<meta property="og:description" content="磁盘空间不足12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758df命令查看当前计算器磁盘空闲情况 df -a 从根目录下开始使用du命令查找出空间占用最大的文件  du -sh /*命令一路追查 [root@test-os testus">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2020-01-13T12:10:36.857Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="linux 笔记">
<meta name="twitter:description" content="磁盘空间不足12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758df命令查看当前计算器磁盘空闲情况 df -a 从根目录下开始使用du命令查找出空间占用最大的文件  du -sh /*命令一路追查 [root@test-os testus">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/04/26/linux-笔记/">



<meta name="referrer" content="never"> ​​​​


  <title>linux 笔记 | 苏生不惑的博客</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">苏生不惑的博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/04/26/linux-笔记/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="苏生不惑">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="苏生不惑的博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">linux 笔记</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-04-26T16:54:15+08:00">
                2019-04-26
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          
            <span class="post-meta-divider">|</span>
            <span class="page-pv"><i class="fa fa-file-o"></i>
            <span class="busuanzi-value" id="busuanzi_value_page_pv"></span>次
            </span>
          

          
            <div class="post-wordcount">
              
                
                  <span class="post-meta-divider">|</span>
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  14.6k 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  67 分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h3 id="磁盘空间不足"><a href="#磁盘空间不足" class="headerlink" title="磁盘空间不足"></a>磁盘空间不足</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line">df命令查看当前计算器磁盘空闲情况</span><br><span class="line"> df -a</span><br><span class="line"> 从根目录下开始使用du命令查找出空间占用最大的文件</span><br><span class="line">  du -sh <span class="comment">/*命令一路追查</span></span><br><span class="line"><span class="comment"> [root@test-os testuser]# df -h   ###物理磁盘空间 查看所有block使用情况</span></span><br><span class="line"><span class="comment"> Filesystem      Size  Used Avail Use% Mounted on</span></span><br><span class="line"><span class="comment"> /dev/sda3       8.8G  8.8G     0 100% /</span></span><br><span class="line"><span class="comment"> tmpfs           931M     0  931M   0% /dev/shm</span></span><br><span class="line"><span class="comment"> /dev/sda1       190M   40M  141M  22% /boot</span></span><br><span class="line"><span class="comment"> [root@test-os testuser]# du -sh /usr/* |grep G  ###查找大文件</span></span><br><span class="line"><span class="comment"> 7.3G    /usr/local</span></span><br><span class="line"><span class="comment"> [root@test-os testuser]# du -sh /usr/local/* |grep G</span></span><br><span class="line"><span class="comment"> 7.3G    /usr/local/bin</span></span><br><span class="line"><span class="comment"> [root@test-os testuser]# du -sh /usr/local/bin/* |grep G</span></span><br><span class="line"><span class="comment"> 7.3G    /usr/local/bin/1g</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment"> [root@test-os testuser]# rm -f /usr/local/bin/1g  ###删除大文件</span></span><br><span class="line"><span class="comment">有些文件删除时还被其它进程占用，此时文件并未真正删除，只是标记为 deleted，只有进程结束后才会将文件真正从磁盘中清除。</span></span><br><span class="line"><span class="comment"> [root@test-os ~]# lsof |grep deleted </span></span><br><span class="line"><span class="comment"> rsyslogd   1250      root    1w      REG                8,3 4888889358     140789 /var/log/messages (deleted)</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment"> [root@test-os ~]# #lsof 显示出系统中被打开的文件 </span></span><br><span class="line"><span class="comment"> [root@test-os ~]# #第一列 软件/服务的名称</span></span><br><span class="line"><span class="comment"> [root@test-os ~]# #第八列 文件的大小 </span></span><br><span class="line"><span class="comment"> [root@test-os ~]# #第10列 文件的名字</span></span><br><span class="line"><span class="comment"> [root@test-os ~]# #第11列 标记（硬链接数为0 进程调用数不为零 就会有 delete)</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment"> ####重启对应的服务 释放磁盘空间 </span></span><br><span class="line"><span class="comment"> [root@test-os ~]# /etc/init.d/rsyslog restart </span></span><br><span class="line"><span class="comment"> --------------------- </span></span><br><span class="line"><span class="comment"> [root@test-os ~]# df -h</span></span><br><span class="line"><span class="comment"> Filesystem      Size  Used Avail Use% Mounted on</span></span><br><span class="line"><span class="comment"> /dev/sda3       8.8G  1.5G  6.9G  18% /</span></span><br><span class="line"><span class="comment"> tmpfs           931M     0  931M   0% /dev/shm</span></span><br><span class="line"><span class="comment"> /dev/sda1       190M   40M  141M  22% /boot</span></span><br><span class="line"><span class="comment"> /tmp/1m        1003K   19K  933K   2% /app/logs</span></span><br><span class="line"><span class="comment"> --------------------- </span></span><br><span class="line"><span class="comment"> # df -ih 节点磁盘空间</span></span><br><span class="line"><span class="comment"> Filesystem Inodes IUsed IFree IUse% Mounted on</span></span><br><span class="line"><span class="comment"> /dev/vda1 1.9M 299K 1.6M 17% /</span></span><br><span class="line"><span class="comment"> udev  123K 299 123K 1% /dev</span></span><br><span class="line"><span class="comment"> tmpfs  126K 249 125K 1% /run</span></span><br><span class="line"><span class="comment"> tmpfs  126K 4 126K 1% /run/lock</span></span><br><span class="line"><span class="comment"> tmpfs  126K 2 126K 1% /run/shm</span></span><br><span class="line"><span class="comment"> 可以看到，inode 区域只被占用了一小部分，还有大量的空间未使用，所以也不是 inode 区域被占满的问题。</span></span><br><span class="line"><span class="comment"> 查看哪个目录占用过大：</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment"> cd /;du  -sh ./* |sort -nr|more</span></span><br><span class="line"><span class="comment"> 发现 /var/spool/postfix/maildrop 这个目录占用了12G 多的空间</span></span><br><span class="line"><span class="comment"> 删除这个目录下的内容(通过管道的方式删除,避免参数过长导致无法执行)：</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment"> ls | xargs rm -f</span></span><br><span class="line"><span class="comment"> lsof test.log</span></span><br><span class="line"><span class="comment"> 这命令只能在文件被写入的时候才能显示内容，最后虽然得到了个进程号，但是因为写完进程就关闭了，所以还是查不到</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment">    for i in /home/*; do echo $i; find $i |wc -l; done</span></span><br><span class="line"><span class="comment"> </span></span><br><span class="line"><span class="comment">    通过该命令可以查看每个用户home下inode的占用情况。如果某个目录下的inode很大，那就是问题所在了。</span></span><br></pre></td></tr></table></figure>
<h3 id="git-push-报错-fatal-HttpRequestException-encountered"><a href="#git-push-报错-fatal-HttpRequestException-encountered" class="headerlink" title="git push 报错 fatal: HttpRequestException encountered."></a>git push 报错 fatal: HttpRequestException encountered.</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">Github 禁用了TLS v1<span class="number">.0</span> and v1<span class="number">.1</span>，必须更新Windows的git凭证管理器</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//github.com/Microsoft/Git-Credential-Manager-for-Windows/releases/tag/v1.18.2</span></span><br><span class="line"></span><br><span class="line">下载并安装后即可解决</span><br></pre></td></tr></table></figure>
<h3 id="pip-install-失败"><a href="#pip-install-失败" class="headerlink" title="pip install 失败"></a>pip install 失败</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line"> pip install myqr</span><br><span class="line">Collecting myqr</span><br><span class="line">  Retrying (Retry(total=<span class="number">4</span>, connect=None, read=None, redirect=None, status=None)) after connection broken by <span class="string">'ProxyError('</span>Cannot connect to proxy.<span class="string">', NewConnectionError('</span>&lt;pip._vendor.urllib3.connection.VerifiedHTTPSConnection object at <span class="number">0x03B22330</span>&gt;: Failed to establish a <span class="keyword">new</span> connection: [WinError <span class="number">10061</span>] 由于目</span><br><span class="line">标计算机积极拒绝，无法连接。<span class="string">'))'</span>: <span class="regexp">/simple/my</span>qr/</span><br><span class="line">打开Internet选项，选择连接–局域网设置  全部取消勾选，问题解决</span><br><span class="line">https:<span class="comment">//blog.csdn.net/u010784236/article/details/51820284</span></span><br></pre></td></tr></table></figure>
<h3 id="awk"><a href="#awk" class="headerlink" title="awk"></a>awk</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">$ echo <span class="string">'this is a test'</span> | awk <span class="string">'&#123;print $0&#125;'</span></span><br><span class="line">$ awk -F <span class="string">':'</span> <span class="string">'&#123; print $1 &#125;'</span> demo.txt</span><br><span class="line">$(NF<span class="number">-1</span>) 代表倒数第二个字段。</span><br><span class="line"> </span><br><span class="line">$ awk -F <span class="string">':'</span> <span class="string">'&#123;print $1, $(NF-1)&#125;'</span> demo.txt</span><br><span class="line"> NR 表示当前处理的是第几行。</span><br><span class="line"> </span><br><span class="line">$ awk -F <span class="string">':'</span> <span class="string">'&#123;print NR ") " $1&#125;'</span> demo.txt</span><br><span class="line">awk -F <span class="string">':'</span> <span class="string">'&#123; print toupper($1) &#125;'</span> demo.txt</span><br><span class="line">awk -F ':' '/usr/ &#123;print $1&#125;' demo.txt #awk ‘条件 动作’ 文件名  print 命令前面是一个正则表达式，只输出包含 usr 的行</span><br><span class="line">awk -F <span class="string">':'</span> <span class="string">'NR % 2 == 1 &#123;print $1&#125;'</span> demo.txt 输出奇数行</span><br><span class="line">awk -F <span class="string">':'</span> <span class="string">'&#123;if ($1 &gt; "m") print $1&#125;'</span> demo.txt</span><br><span class="line">$ awk -F <span class="string">':'</span> <span class="string">'&#123;if ($1 &gt; "m") print $1; else print "---"&#125;'</span> demo.txt</span><br></pre></td></tr></table></figure>
<h3 id="批量删除-DS-Store-文件"><a href="#批量删除-DS-Store-文件" class="headerlink" title="批量删除 .DS_Store 文件"></a>批量删除 .DS_Store 文件</h3><p><code>find /home/path -name &quot;.DS_Store&quot; -type f -delete</code></p>
<h3 id="查看硬盘及内存空间"><a href="#查看硬盘及内存空间" class="headerlink" title="查看硬盘及内存空间"></a>查看硬盘及内存空间</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"> </span><br><span class="line"># 查看内存及swap大小</span><br><span class="line">free -m</span><br><span class="line"># 查看当前文件夹下所有文件大小（包括子文件夹）</span><br><span class="line">du -sh</span><br><span class="line"># 查看指定文件夹下所有文件大小</span><br><span class="line">du -h /tmp</span><br><span class="line"># 查看tmp目录(包含子目录)的大小</span><br><span class="line">du -ah /tmp</span><br><span class="line"></span><br><span class="line"># 查看指定文件夹大小</span><br><span class="line">du -hs ftp</span><br><span class="line"># 查看磁盘剩余空间</span><br><span class="line">df -hl</span><br><span class="line"># 查看每个根路径的分区大小</span><br><span class="line">df -h</span><br><span class="line"># 返回该目录的大小</span><br><span class="line">du -sh [目录名]</span><br><span class="line"># 返回该文件夹总M数</span><br><span class="line">du -sm [文件夹]</span><br></pre></td></tr></table></figure>
<h3 id="统计文件或目录的个数"><a href="#统计文件或目录的个数" class="headerlink" title="统计文件或目录的个数"></a>统计文件或目录的个数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"># 统计文件夹下文件的个数</span><br><span class="line">ls -l | grep <span class="string">'^-'</span> | wc -l</span><br><span class="line"># 统计文件夹下目录的个数</span><br><span class="line">ls -l | grep <span class="string">'^d'</span> | wc -l</span><br><span class="line"># 统计文件夹下文件的个数(包括子文件夹里的)</span><br><span class="line">ls -lR | grep <span class="string">'^-'</span> | wc -l</span><br><span class="line"># 统计文件夹下目录的个数(包括子文件夹里的)</span><br><span class="line">ls -lR | grep <span class="string">'^d'</span> | wc -l</span><br><span class="line"># 统计/var/www目录下的所有py文件</span><br><span class="line">ls -l /<span class="keyword">var</span>/www | grep py | wc -l</span><br><span class="line"># 统计/var/www目录下(包括子文件夹里的)的所有py文件</span><br><span class="line">ls -lR /<span class="keyword">var</span>/www | grep py | wc -l</span><br></pre></td></tr></table></figure>
<h3 id="查看CPU和内存占用"><a href="#查看CPU和内存占用" class="headerlink" title="查看CPU和内存占用"></a>查看CPU和内存占用</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"># CPU占用最多的前10个进程： </span><br><span class="line">ps auxw|head <span class="number">-1</span>;ps auxw|sort -rn -k3|head <span class="number">-10</span> </span><br><span class="line"># 内存消耗最多的前10个进程 </span><br><span class="line">ps auxw|head <span class="number">-1</span>;ps auxw|sort -rn -k4|head <span class="number">-10</span> </span><br><span class="line"># 虚拟内存使用最多的前10个进程 </span><br><span class="line">ps auxw|head <span class="number">-1</span>;ps auxw|sort -rn -k5|head <span class="number">-10</span></span><br><span class="line"> 按内存占用对进程排序</span><br><span class="line">ps auxw --sort=rss</span><br><span class="line"># 按CPU占用对进程排序</span><br><span class="line">ps auxw --sort=%cpu</span><br><span class="line"></span><br><span class="line">查看所有运行的进程</span><br><span class="line">ps -A</span><br></pre></td></tr></table></figure>
<h3 id="curl"><a href="#curl" class="headerlink" title="curl"></a>curl</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">强制指定本地端口</span><br><span class="line">curl --local-port <span class="number">51</span> http:<span class="comment">//web.example.com</span></span><br><span class="line"></span><br><span class="line"># 查看连接的详细信息</span><br><span class="line"># --trace-time 跟踪/详细输出时，添加时间戳</span><br><span class="line">curl -Sv --trace-time http:<span class="comment">//web.example.com</span></span><br></pre></td></tr></table></figure>
<h3 id="连接你服务器-top10-用户端的-IP-地址"><a href="#连接你服务器-top10-用户端的-IP-地址" class="headerlink" title="连接你服务器 top10 用户端的 IP 地址"></a>连接你服务器 top10 用户端的 IP 地址</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">netstat -nat | awk <span class="string">'&#123;print $5&#125;'</span> | awk -F <span class="string">':'</span> <span class="string">'&#123;print $1&#125;'</span> | sort | uniq -c | sort -rn | head -n <span class="number">10</span></span><br></pre></td></tr></table></figure>
<h3 id="最常用的10个命令"><a href="#最常用的10个命令" class="headerlink" title="最常用的10个命令"></a>最常用的10个命令</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">cat .bash_history | sort | uniq -c | sort -rn | head -n <span class="number">10</span> (or cat .zhistory | sort | uniq -c | sort -rn | head -n <span class="number">10</span></span><br></pre></td></tr></table></figure>
<h3 id="alias"><a href="#alias" class="headerlink" title="alias"></a>alias</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">alias nis=<span class="string">"npm install --save "</span></span><br><span class="line">alias svim=<span class="string">'sudo vim'</span></span><br><span class="line">alias mkcd=<span class="string">'foo()&#123; mkdir -p "$1"; cd "$1" &#125;; foo '</span></span><br><span class="line">alias install=<span class="string">'sudo apt get install'</span></span><br><span class="line">alias update=<span class="string">'sudo apt-get update; sudo apt-get upgrade'</span></span><br><span class="line">alias ..=<span class="string">"cd .."</span></span><br><span class="line">alias ...=<span class="string">"cd ..; cd .."</span></span><br><span class="line">alias www=<span class="string">'python -m SimpleHTTPServer 8000'</span></span><br><span class="line">alias sock5=<span class="string">'ssh -D 8080 -q -C -N -f user@your.server'</span></span><br></pre></td></tr></table></figure>
<h3 id="wget"><a href="#wget" class="headerlink" title="wget"></a>wget</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">wget http:<span class="comment">//www.openss7.org/repos/tarballs/strx25-0.9.2.1.ta</span></span><br><span class="line">$ wget -b http:<span class="comment">//www.openss7.org/repos/tarballs/strx25-0.9.2.1.tar.bz2</span></span><br><span class="line">Continuing <span class="keyword">in</span> background, pid <span class="number">1984.</span></span><br><span class="line">Output will be written to <span class="string">`wget-log'.</span></span><br><span class="line"><span class="string">wget -i download-file-list.txt</span></span><br></pre></td></tr></table></figure>
<h3 id="防火墙"><a href="#防火墙" class="headerlink" title="防火墙"></a>防火墙</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">sudo firewall-cmd --zone=public --add-port=<span class="number">60001</span>/udp --permanent</span><br><span class="line">sudo firewall-cmd --reload</span><br><span class="line">#之后检查新的防火墙规则</span><br><span class="line">firewall-cmd --list-all</span><br><span class="line"></span><br><span class="line"><span class="comment">//临时关闭防火墙,重启后会重新自动打开</span></span><br><span class="line">systemctl restart firewalld</span><br><span class="line"><span class="comment">//检查防火墙状态</span></span><br><span class="line">firewall-cmd --state</span><br><span class="line">firewall-cmd --list-all</span><br><span class="line"><span class="comment">//Disable firewall</span></span><br><span class="line">systemctl disable firewalld</span><br><span class="line">systemctl stop firewalld</span><br><span class="line">systemctl status firewalld</span><br><span class="line"><span class="comment">//Enable firewall</span></span><br><span class="line">systemctl enable firewalld</span><br><span class="line">systemctl start firewalld</span><br><span class="line">systemctl status firewalld</span><br></pre></td></tr></table></figure>
<h3 id="显示-Path-环境变量"><a href="#显示-Path-环境变量" class="headerlink" title="显示 Path 环境变量"></a>显示 Path 环境变量</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"> $ echo $PATH | tr : \\n</span><br><span class="line">/data2/node-v6<span class="number">.11</span><span class="number">.0</span>-linux-x64<span class="comment">//bin</span></span><br><span class="line">/usr/bin</span><br><span class="line">/bin</span><br><span class="line">/usr/sbin</span><br><span class="line">/sbin</span><br><span class="line">/usr/local/bin</span><br><span class="line">/usr/local/sbin</span><br><span class="line">/data0/opt/python27/bin</span><br></pre></td></tr></table></figure>
<h3 id="判断字符串包含"><a href="#判断字符串包含" class="headerlink" title="判断字符串包含"></a>判断字符串包含</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> [[ $tar =~ tar.gz ]];then echo <span class="string">"包含"</span>;fi</span><br></pre></td></tr></table></figure>
<h3 id="快速修改后缀名字"><a href="#快速修改后缀名字" class="headerlink" title="快速修改后缀名字"></a>快速修改后缀名字</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">ll</span><br><span class="line">CentOS-base.repo.repo.bak</span><br><span class="line">epel.repo.repo.bak</span><br><span class="line"></span><br><span class="line">ls *.bak|awk -F. <span class="string">'&#123;print $1&#125;'</span>|xargs -t -i mv &#123;&#125;.repo.repo.bak &#123;&#125;.repo</span><br></pre></td></tr></table></figure>
<h3 id="数值排序"><a href="#数值排序" class="headerlink" title="数值排序"></a>数值排序</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">sort -t <span class="string">":"</span> -k <span class="number">3</span> -n /etc/passwd</span><br></pre></td></tr></table></figure>
<h3 id="清理httpd服务日志超过3天的内容"><a href="#清理httpd服务日志超过3天的内容" class="headerlink" title="清理httpd服务日志超过3天的内容"></a>清理httpd服务日志超过3天的内容</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0</span> <span class="number">5</span> * * * <span class="regexp">/usr/</span>bin/find /<span class="keyword">var</span>/log/httpd/ -type f -mtime +<span class="number">3</span> -exec rm -rf &#123;&#125; \;</span><br></pre></td></tr></table></figure>
<h3 id="awk获取json"><a href="#awk获取json" class="headerlink" title="awk获取json"></a>awk获取json</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">&#123;<span class="string">"name"</span>: <span class="string">"michael"</span>, <span class="string">"sex"</span>: <span class="string">"male"</span>, <span class="string">"pkg_url"</span>: <span class="string">"www.github.com"</span>, <span class="string">"number"</span>: <span class="string">"888"</span>&#125;</span><br><span class="line"></span><br><span class="line">pkg_url=$(echo $env | awk -F <span class="string">"pkg_url\": \""</span> <span class="string">'&#123;print $2&#125;'</span> | awk -F <span class="string">"\","</span> <span class="string">'&#123;print $1&#125;'</span>)</span><br><span class="line">echo $pkg_url</span><br><span class="line">www.github.com</span><br></pre></td></tr></table></figure>
<h3 id="cpu"><a href="#cpu" class="headerlink" title="cpu"></a>cpu</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">查看 CPU 的型号</span><br><span class="line"></span><br><span class="line"> cat /proc/cpuinfo | grep <span class="string">'model name'</span> | sort | uniq</span><br><span class="line">查看 CPU 颗数</span><br><span class="line"></span><br><span class="line">实际 Server 中插槽上的 CPU 个数，物理 cpu 数量，可以数不重复的 physical id 个数。</span><br><span class="line"></span><br><span class="line">cat /proc/cpuinfo | grep <span class="string">'physical id'</span> | sort | uniq | wc -l</span><br><span class="line">查看 CPU 核数</span><br><span class="line"></span><br><span class="line">一颗 CPU 上面能处理数据的芯片组的数量。</span><br><span class="line"></span><br><span class="line">cat /proc/cpuinfo |grep <span class="string">"cores"</span>|uniq|awk <span class="string">'&#123;print $4&#125;'</span></span><br><span class="line">top 命令查询出来的就是逻辑 CPU 的数量。</span><br><span class="line"></span><br><span class="line">cat /proc/cpuinfo |grep <span class="string">"processor"</span>|wc -l</span><br><span class="line">https:<span class="comment">//learnku.com/articles/32681</span></span><br></pre></td></tr></table></figure>
<h3 id="查看系统负载"><a href="#查看系统负载" class="headerlink" title="查看系统负载"></a>查看系统负载</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br></pre></td><td class="code"><pre><span class="line">$ uptime\</span><br><span class="line"><span class="number">16</span>:<span class="number">33</span>:<span class="number">56</span> up <span class="number">69</span> days,  <span class="number">5</span>:<span class="number">10</span>,  <span class="number">1</span> user,  load average: <span class="number">0.14</span>, <span class="number">0.24</span>, <span class="number">0.29</span></span><br><span class="line">以上信息的解析如下：</span><br><span class="line"></span><br><span class="line"><span class="number">16</span>:<span class="number">33</span>:<span class="number">56</span> : 当前时间</span><br><span class="line">up <span class="number">69</span> days, <span class="number">5</span>:<span class="number">10</span> : 系统运行了 <span class="number">69</span> 天 <span class="number">5</span> 小时 <span class="number">10</span> 分</span><br><span class="line"><span class="number">1</span> user : 当前有 <span class="number">1</span> 个用户登录了系统 load average: <span class="number">0.14</span>, <span class="number">0.24</span>, <span class="number">0.29</span> : 系统在过去 <span class="number">1</span> 分钟内，<span class="number">5</span> 分钟内，<span class="number">15</span> 分钟内的平均负载</span><br><span class="line">load average: <span class="number">0.14</span>, <span class="number">0.24</span>, <span class="number">0.29</span> : 系统在过去 <span class="number">1</span> 分钟内，<span class="number">5</span> 分钟内，<span class="number">15</span> 分钟内的平均负载</span><br><span class="line">平均负载解析</span><br><span class="line"></span><br><span class="line">查看逻辑 CPU 核心数：</span><br><span class="line"></span><br><span class="line">$ grep <span class="string">'model name'</span> /proc/cpuinfo | wc -l\</span><br><span class="line"><span class="number">1</span>\</span><br><span class="line">运行结果表示，有 <span class="number">1</span> 个逻辑 CPU 核心。以 <span class="number">1</span> 个 CPU 核心为例，假设 CPU 每分钟最多处理 <span class="number">100</span> 个进程 –</span><br><span class="line"></span><br><span class="line">load=<span class="number">0</span>，没有进程需要 CPU</span><br><span class="line">load=<span class="number">0.5</span>，CPU 处理了 <span class="number">50</span> 个进程</span><br><span class="line">load=<span class="number">1</span>, CPU 处理了 <span class="number">100</span> 个进程，这时 CPU 已被占满，但系统还是能顺畅运作的</span><br><span class="line">load=<span class="number">1.5</span>, CPU 处理了 <span class="number">100</span> 个进程，还有 <span class="number">50</span> 个进程正在排除等着 CPU 处理，这时，CPU 已经超负荷工作了</span><br><span class="line">为了系统顺畅运行，load 值最好不要超过 <span class="number">1.0</span>，这样就没有进程需要等待了，所有进程都能第一时间得到处理。\</span><br><span class="line">很显然，<span class="number">1.0</span> 是一个关键值，超过这个值，系统就不在最佳状态了。 一般 <span class="number">0.7</span> 是一个比较理想的值。\</span><br><span class="line">另外，load 值的健康状态还跟系统 CPU 核心数相关，如果 CPU 核心数为 <span class="number">2</span>，那么 load 值健康值应该为 <span class="number">2</span>，以此类推。 \</span><br><span class="line">评价系统的负载一般采用 <span class="number">15</span> 分钟内的那个平均负载值。</span><br><span class="line"></span><br><span class="line">二、w 命令</span><br><span class="line"></span><br><span class="line">$ w\</span><br><span class="line"> <span class="number">17</span>:<span class="number">47</span>:<span class="number">40</span> up <span class="number">69</span> days,  <span class="number">6</span>:<span class="number">24</span>,  <span class="number">1</span> user,  load average: <span class="number">0.46</span>, <span class="number">0.26</span>, <span class="number">0.25</span>\</span><br><span class="line">USER     TTY      FROM              LOGIN@   IDLE   JCPU   PCPU WHAT\</span><br><span class="line">lvinkim  pts/<span class="number">0</span>    <span class="number">14.18</span><span class="number">.144</span><span class="number">.2</span>      <span class="number">15</span>:<span class="number">55</span>    <span class="number">0.00</span>s  <span class="number">0.02</span>s  <span class="number">0.00</span>s w</span><br><span class="line">第 <span class="number">1</span> 行：与 uptime 一相同。 \</span><br><span class="line">第 <span class="number">2</span> 行以下，当前登录用户的列表。</span><br><span class="line"></span><br><span class="line">三、top 命令</span><br><span class="line"></span><br><span class="line">$ top\</span><br><span class="line">top - <span class="number">17</span>:<span class="number">51</span>:<span class="number">23</span> up <span class="number">69</span> days,  <span class="number">6</span>:<span class="number">28</span>,  <span class="number">1</span> user,  load average: <span class="number">0.31</span>, <span class="number">0.30</span>, <span class="number">0.26</span>\</span><br><span class="line">Tasks:  <span class="number">99</span> total,   <span class="number">1</span> running,  <span class="number">98</span> sleeping,   <span class="number">0</span> stopped,   <span class="number">0</span> zombie\</span><br><span class="line">Cpu(s):  <span class="number">2.3</span>%us,  <span class="number">0.2</span>%sy,  <span class="number">0.0</span>%ni, <span class="number">97.4</span>%id,  <span class="number">0.0</span>%wa,  <span class="number">0.0</span>%hi,  <span class="number">0.0</span>%si,  <span class="number">0.0</span>%st\</span><br><span class="line">Mem:   <span class="number">1922244</span>k total,  <span class="number">1737480</span>k used,   <span class="number">184764</span>k free,   <span class="number">208576</span>k buffers\</span><br><span class="line">Swap:        <span class="number">0</span>k total,        <span class="number">0</span>k used,        <span class="number">0</span>k free,   <span class="number">466732</span>k cached\</span><br><span class="line">\</span><br><span class="line">  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND                                                                \</span><br><span class="line">    <span class="number">1</span> root      <span class="number">20</span>   <span class="number">0</span> <span class="number">19232</span> <span class="number">1004</span>  <span class="number">708</span> S  <span class="number">0.0</span>  <span class="number">0.1</span>   <span class="number">0</span>:<span class="number">01.17</span> init                                                                    \</span><br><span class="line">    <span class="number">2</span> root      <span class="number">20</span>   <span class="number">0</span>     <span class="number">0</span>    <span class="number">0</span>    <span class="number">0</span> S  <span class="number">0.0</span>  <span class="number">0.0</span>   <span class="number">0</span>:<span class="number">00.01</span> kthreadd                                                                \</span><br><span class="line">...</span><br><span class="line">第 <span class="number">1</span> 行：与 uptime 一相同。</span><br><span class="line"></span><br><span class="line">第 <span class="number">2</span> 行：进程数信息。</span><br><span class="line"></span><br><span class="line">Tasks: <span class="number">99</span> total : 总共有 <span class="number">99</span> 个进程</span><br><span class="line"><span class="number">1</span> running : <span class="number">1</span> 个进程正在占用 CPU</span><br><span class="line"><span class="number">98</span> sleeping : <span class="number">98</span> 个睡眠进程</span><br><span class="line"><span class="number">0</span> stopped : <span class="number">0</span> 个停止的进程</span><br><span class="line"><span class="number">0</span> zombie : <span class="number">0</span> 个僵尸进程</span><br><span class="line">第 <span class="number">3</span> 行 : CPU 使用率</span><br><span class="line"></span><br><span class="line">us (user): 非 nice 用户进程占用 CPU 的比率</span><br><span class="line">sy (system): 内核、内核进程占用 CPU 的比率</span><br><span class="line">ni (nice): 用户进程空间内改变过优先级的进程占用 CPU 比率</span><br><span class="line">id (idle): CPU 空闲比率，如果系统缓慢而这个值很高，说明系统慢的原因不是 CPU 负载高</span><br><span class="line">wa (iowait): CPU 等待执行 I/O 操作的时间比率，该指标可以用来排查磁盘 I/O 的问题，通常结合 wa 和 id 判断</span><br><span class="line">hi (Hardware IRQ): CPU 处理硬件中断所占时间的比率</span><br><span class="line">si (Software Interrupts): CPU 处理软件中断所占时间的比率</span><br><span class="line">st (steal): 流逝的时间，虚拟机中的其他任务所占 CPU 时间的比率</span><br><span class="line">需要注意的一些情形：</span><br><span class="line"></span><br><span class="line">用户进程 us 占比高，I/O 操作 wa 低：说明系统缓慢的原因在于进程占用大量 CPU，通常还会伴有教低的空闲比率 id，说明 CPU 空转时间很少。</span><br><span class="line">I/O 操作 wa 低，空闲比率 id 高：可以排除 CPU 资源瓶颈的可能。</span><br><span class="line">I/O 操作 wa 高：说明 I/O 占用了大量的 CPU 时间，需要检查交换空间的使用，交换空间位于磁盘上，性能远低于内存，当内存耗尽开始使用交换空间时，将会给性能带来严重影响，所以对于性能要求较高的服务器，一般建议关闭交换空间。另一方面，如果内存充足，但 wa 很高，说明需要检查哪个进程占用了大量的 I/O 资源。</span><br><span class="line">更多负载情形，可在实际中灵活判断。</span><br><span class="line"></span><br><span class="line">四、iostat 命令</span><br><span class="line"></span><br><span class="line">iostat 命令可以查看系统分区的 IO 使用情况</span><br><span class="line"></span><br><span class="line">$ iostat \</span><br><span class="line">Linux <span class="number">2.6</span><span class="number">.32</span><span class="number">-573.22</span><span class="number">.1</span>.el6.x86_64 (sgs02)   <span class="number">01</span>/<span class="number">20</span>/<span class="number">2017</span>     _x86_64_   (<span class="number">1</span> CPU)\</span><br><span class="line">\</span><br><span class="line">avg-cpu:  %user   %nice %system %iowait  %steal   %idle\</span><br><span class="line">           <span class="number">2.29</span>    <span class="number">0.00</span>    <span class="number">0.25</span>    <span class="number">0.04</span>    <span class="number">0.00</span>   <span class="number">97.41</span>\</span><br><span class="line">\</span><br><span class="line">Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn\</span><br><span class="line">vda               <span class="number">1.15</span>         <span class="number">3.48</span>        <span class="number">21.88</span>   <span class="number">21016084</span>  <span class="number">131997520</span></span><br><span class="line">一些值得注意的 IO 指标 :</span><br><span class="line"></span><br><span class="line">Device : 磁盘名称</span><br><span class="line">tps : 每秒 I/O 传输请求量</span><br><span class="line">Blk_read/s : 每秒读取多少块，查看块大小可参考命令 tune2fs</span><br><span class="line">Blk_wrtn/s : 每秒写取多少块</span><br><span class="line">Blk_read : 一共读了多少块</span><br><span class="line">–Blk_wrtn : 一共写了多少块</span><br><span class="line">五、iotop 命令</span><br><span class="line"></span><br><span class="line">iotop 命令类似于 top 命令，但是显示的是各个进程的 I/O 情况，对于定位 I/O 操作较重的进程有比较大的作用。\</span><br><span class="line"></span><br><span class="line"># iotop\</span><br><span class="line">Total DISK READ: <span class="number">0.00</span> B/s | Total DISK WRITE: <span class="number">774.52</span> K/s\</span><br><span class="line">  TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN     IO&gt;    COMMAND                                                                \</span><br><span class="line">  <span class="number">272</span> be/<span class="number">3</span> root        <span class="number">0.00</span> B/s    <span class="number">0.00</span> B/s  <span class="number">0.00</span> %  <span class="number">4.86</span> % [jbd2/vda1<span class="number">-8</span>]\</span><br><span class="line"> <span class="number">9072</span> be/<span class="number">4</span> mysql       <span class="number">0.00</span> B/s  <span class="number">268.71</span> K/s  <span class="number">0.00</span> %  <span class="number">0.00</span> % mysqld\</span><br><span class="line"> <span class="number">5058</span> be/<span class="number">4</span> lvinkim     <span class="number">0.00</span> B/s    <span class="number">3.95</span> K/s  <span class="number">0.00</span> %  <span class="number">0.00</span> % php-fpm: pool www\</span><br><span class="line">    <span class="number">1</span> be/<span class="number">4</span> root        <span class="number">0.00</span> B/s    <span class="number">0.00</span> B/s  <span class="number">0.00</span> %  <span class="number">0.00</span> % init</span><br><span class="line">可以看到不同任务的读写强度。</span><br><span class="line"></span><br><span class="line">六、sysstat 工具</span><br><span class="line"></span><br><span class="line">很多时候当检测到或者知道历史的高负载状况时，可能需要回放历史监控数据，这时 sar 命令就派上用场了，sar 命令同样来自 sysstat 工具包，可以记录系统的 CPU 负载、I/O 状况和内存使用记录，便于历史数据的回放。</span><br><span class="line"></span><br><span class="line">sysstat 的配置文件在 /etc/sysconfig/sysstat 文件，历史日志的存放位置为 /<span class="keyword">var</span>/log/sa\</span><br><span class="line">统计信息都是每 <span class="number">10</span> 分钟记录一次，每天的 <span class="number">23</span>:<span class="number">59</span> 会分割统计文件，这些操作的频率都在 /etc/cron.d/sysstat 文件配置。\</span><br><span class="line"></span><br><span class="line">七、sar 命令</span><br><span class="line"></span><br><span class="line">使用 sar 命令查看当天 CPU 使用：</span><br><span class="line"></span><br><span class="line">$ sar\</span><br><span class="line">Linux <span class="number">2.6</span><span class="number">.32</span><span class="number">-431.23</span><span class="number">.3</span>.el6.x86_64 (szs01)   <span class="number">01</span>/<span class="number">20</span>/<span class="number">2017</span>     _x86_64_   (<span class="number">1</span> CPU)\</span><br><span class="line">\</span><br><span class="line"><span class="number">10</span>:<span class="number">50</span>:<span class="number">01</span> AM     CPU     %user     %nice   %system   %iowait    %steal     %idle\</span><br><span class="line"><span class="number">11</span>:<span class="number">00</span>:<span class="number">01</span> AM     all      <span class="number">0.45</span>      <span class="number">0.00</span>      <span class="number">0.22</span>      <span class="number">0.40</span>      <span class="number">0.00</span>     <span class="number">98.93</span>\</span><br><span class="line">Average:        all      <span class="number">0.45</span>      <span class="number">0.00</span>      <span class="number">0.22</span>      <span class="number">0.40</span>      <span class="number">0.00</span>     <span class="number">98.93</span></span><br><span class="line">使用 sar 命令查看当天内存使用：</span><br><span class="line"></span><br><span class="line">$ sar -r\</span><br><span class="line">Linux <span class="number">2.6</span><span class="number">.32</span><span class="number">-431.23</span><span class="number">.3</span>.el6.x86_64 (szs01)   <span class="number">01</span>/<span class="number">20</span>/<span class="number">2017</span>     _x86_64_   (<span class="number">1</span> CPU)\</span><br><span class="line">\</span><br><span class="line"><span class="number">10</span>:<span class="number">50</span>:<span class="number">01</span> AM kbmemfree kbmemused  %memused kbbuffers  kbcached  kbcommit   %commit\</span><br><span class="line"><span class="number">11</span>:<span class="number">00</span>:<span class="number">01</span> AM     <span class="number">41292</span>    <span class="number">459180</span>     <span class="number">91.75</span>     <span class="number">44072</span>    <span class="number">164620</span>    <span class="number">822392</span>    <span class="number">164.32</span>\</span><br><span class="line">Average:        <span class="number">41292</span>    <span class="number">459180</span>     <span class="number">91.75</span>     <span class="number">44072</span>    <span class="number">164620</span>    <span class="number">822392</span>    <span class="number">164.32</span></span><br><span class="line">使用 sar 命令查看当天 IO 统计记录：</span><br><span class="line"></span><br><span class="line">$ sar -b\</span><br><span class="line">Linux <span class="number">2.6</span><span class="number">.32</span><span class="number">-431.23</span><span class="number">.3</span>.el6.x86_64 (szs01)   <span class="number">01</span>/<span class="number">20</span>/<span class="number">2017</span>     _x86_64_   (<span class="number">1</span> CPU)\</span><br><span class="line">\</span><br><span class="line"><span class="number">10</span>:<span class="number">50</span>:<span class="number">01</span> AM       tps      rtps      wtps   bread/s   bwrtn/s\</span><br><span class="line"><span class="number">11</span>:<span class="number">00</span>:<span class="number">01</span> AM      <span class="number">3.31</span>      <span class="number">2.14</span>      <span class="number">1.17</span>     <span class="number">37.18</span>     <span class="number">16.84</span>\</span><br><span class="line">Average:         <span class="number">3.31</span>      <span class="number">2.14</span>      <span class="number">1.17</span>     <span class="number">37.18</span>     <span class="number">16.84</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/31718</span></span><br></pre></td></tr></table></figure>
<h3 id="秘钥登录"><a href="#秘钥登录" class="headerlink" title="秘钥登录"></a>秘钥登录</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line">ssh-keygen -t rsa -C <span class="string">'youxiang@aliyun.com'</span></span><br><span class="line">scp -P &lt;端口号&gt; ~<span class="regexp">/.ssh/i</span>d_rsa.pub &lt;用户名&gt;@&lt;ip地址&gt;:<span class="regexp">/home/i</span>d_rsa.pub</span><br><span class="line">cat /home/id_rsa.pub &gt;&gt; ~<span class="regexp">/.ssh/</span>authorized_keys</span><br><span class="line"></span><br><span class="line">如果在 家目录 没有 .ssh 目录或 authorized_keys 文件，可以创建一下，并授予 authorized_keys 文件 <span class="number">600</span> 权限</span><br><span class="line">ssh root@<span class="number">114.11</span><span class="number">.11</span><span class="number">.111</span></span><br><span class="line">vi ~<span class="regexp">/.ssh/</span>config</span><br><span class="line"></span><br><span class="line">Host            jd            #自定义别名</span><br><span class="line">HostName        114.11.11.110         #替换为你的ssh服务器ip或domain</span><br><span class="line">Port            22             #ssh服务器端口，默认为22</span><br><span class="line">User            root             #ssh服务器用户名</span><br><span class="line">IdentityFile    ~/.ssh/id_rsa    #第一个步骤生成的公钥文件对应的私钥文件</span><br><span class="line">此时就可以使用 ssh jd 进行登录</span><br><span class="line">cd /etc/ssh/</span><br><span class="line"></span><br><span class="line">修改 SSH 的配置文件 vi sshd_config</span><br><span class="line"></span><br><span class="line">RSAAuthentication yes</span><br><span class="line">PubkeyAuthentication yes</span><br><span class="line">AuthorizedKeysFile      .ssh/authorized_keys</span><br><span class="line">#AuthorizedKeysCommand none</span><br><span class="line">#AuthorizedKeysCommandRunAs nobody</span><br><span class="line"></span><br><span class="line">#默认PasswordAuthentication 为yes,即允许密码登录，改为no后，禁止密码登录</span><br><span class="line">PasswordAuthentication no </span><br><span class="line">重启 ssh 服务</span><br><span class="line"></span><br><span class="line">systemctl restart sshd.service</span><br><span class="line">https:<span class="comment">//learnku.com/articles/30438</span></span><br></pre></td></tr></table></figure>
<h3 id="生成二维码"><a href="#生成二维码" class="headerlink" title="生成二维码"></a>生成二维码</h3><figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">第一种方法： qrencode</span><br><span class="line">#安装，记得加epel yum源</span><br><span class="line">[root@localhost ~]# yum install libpng libpng-devel qrencode -y</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#格式</span><br><span class="line">Usage: qrencode [OPTION]... [STRING]</span><br><span class="line">OPTIONS：</span><br><span class="line">-o：输出的二维码文件名。如test.png。需要以.png结尾。-表示输出到控制台。</span><br><span class="line">-s：指定图片大小。默认为<span class="number">3</span>个像素。</span><br><span class="line">-t：指定产生的图片类型。默认为PNG。可以是PNG/ANSI/ANSI256/ASCIIi/UTF8等。如果需要输出到控制台，可以用ANSI、ANSI256等</span><br><span class="line">STRING：可以是text、url等</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">#使用</span><br><span class="line">注：输出的二维码图片大小取决于，内容的多少，且不能换行</span><br><span class="line"></span><br><span class="line"># 将“http://jinchuang.org”网址转换为二维码并保存在qrcode.png图片中</span><br><span class="line">[root@localhost ~]# qrencode -o qrcode.png "http://jinchuang.org"</span><br><span class="line"></span><br><span class="line"># 在终端下无法查看png图片，所以可以使用ANSI生成</span><br><span class="line">[root@localhost ~]# echo "your input words" | qrencode -o - -t ANSI</span><br><span class="line"></span><br><span class="line"># 也可以将需要转换的文字保存为xx.txt文件，之后再转换</span><br><span class="line">[root@localhost ~]# cat xx.txt | qrencode -o - -t ANSI</span><br><span class="line"></span><br><span class="line">第二种方法：</span><br><span class="line">[root@localhost ~]# printf "http://jinchuang.org" | curl -F-=\&lt;- qrenco.de</span><br></pre></td></tr></table></figure>
<h3 id="es-Kibana"><a href="#es-Kibana" class="headerlink" title="es Kibana"></a>es Kibana</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">[root@localhost ~]# cd /source</span><br><span class="line">[root@localhost source]# wget https://artifacts.elastic.co/downloads/kibana/kibana-5.6.0-linux-x86_64.tar.gz</span><br><span class="line">[root@localhost source]# tar xf kibana-5.6.0-linux-x86_64.tar.gz  -C /elk/</span><br><span class="line">[root@localhost source]# cd /elk/</span><br><span class="line">[root@localhost elk]# mv kibana-5.6.0-linux-x86_64/ kibana</span><br><span class="line"></span><br><span class="line">#修改配置文件</span><br><span class="line">[root@localhost elk]# vim kibana/config/kibana.yml</span><br><span class="line">server.port: <span class="number">5601</span></span><br><span class="line">server.host: <span class="string">"0.0.0.0"</span></span><br><span class="line">elasticsearch.url: <span class="string">"http://127.0.0.1:9200"</span></span><br><span class="line"></span><br><span class="line">#启动</span><br><span class="line">[root@localhost elk]# /elk/kibana/bin/kibana &amp;</span><br><span class="line">[<span class="number">1</span>] <span class="number">31948</span></span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.064</span>] [info][status][plugin:kibana@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> uninitialized to green - Ready</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.149</span>] [info][status][plugin:elasticsearch@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> uninitialized to yellow - Waiting <span class="keyword">for</span> Elasticsearch</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.190</span>] [info][status][plugin:<span class="built_in">console</span>@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> uninitialized to green - Ready</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.235</span>] [info][status][plugin:metrics@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> uninitialized to green - Ready</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.435</span>] [info][status][plugin:timelion@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> uninitialized to green - Ready</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.447</span>] [info][status][plugin:elasticsearch@<span class="number">5.6</span><span class="number">.0</span>] Status changed <span class="keyword">from</span> yellow to green - Kibana index ready</span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.449</span>] [info][listening] Server running at http:<span class="comment">//0.0.0.0:5601</span></span><br><span class="line">  log   [<span class="number">05</span>:<span class="number">53</span>:<span class="number">04.452</span>] [info][status][ui settings] Status changed <span class="keyword">from</span> uninitialized to green - Ready</span><br><span class="line"></span><br><span class="line">#查看进程和端口</span><br><span class="line">[root@localhost elk]# ps -ef|grep kibana</span><br><span class="line">root     <span class="number">31948</span> <span class="number">31038</span> <span class="number">12</span> <span class="number">13</span>:<span class="number">52</span> pts/<span class="number">3</span>    <span class="number">00</span>:<span class="number">00</span>:<span class="number">04</span> /elk/kibana/bin/../node/bin/node --no-warnings /elk/kibana/bin/../src/cli</span><br><span class="line"></span><br><span class="line">[root@localhost elk]# netstat -lntp </span><br><span class="line">Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    </span><br><span class="line">tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:<span class="number">9100</span>            <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:*               LISTEN      <span class="number">28361</span>/grunt         </span><br><span class="line">tcp        <span class="number">0</span>      <span class="number">0</span> <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:<span class="number">22</span>              <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:*               LISTEN      <span class="number">14146</span>/sshd      </span><br><span class="line"></span><br><span class="line">https:<span class="comment">//me.jinchuang.org/archives/319.html</span></span><br></pre></td></tr></table></figure>
<h3 id="随机数生成"><a href="#随机数生成" class="headerlink" title="随机数生成"></a>随机数生成</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">(<span class="number">1</span>)  echo $(($RANDOM))          通过系统环境变量</span><br><span class="line"></span><br><span class="line">(<span class="number">2</span>)  echo $RANDOM | md5sum|cut -c <span class="number">1</span><span class="number">-8</span></span><br><span class="line"></span><br><span class="line">(<span class="number">3</span>)  openssl rand -base64 <span class="number">65</span>         openssl产生随机数</span><br><span class="line"></span><br><span class="line">(<span class="number">4</span>)  date +%s%N          通过时间获取随机数</span><br><span class="line"></span><br><span class="line">(<span class="number">5</span>)  head /dev/urandom |cksum            设备随机数</span><br><span class="line"></span><br><span class="line">(<span class="number">6</span>)  cat /proc/sys/kernel/random/uuid           uuid随机数</span><br><span class="line"></span><br><span class="line">(<span class="number">7</span>)  mkpasswd -l <span class="number">12</span> -d <span class="number">5</span>             expect随机数，需要安装expect</span><br></pre></td></tr></table></figure>
<h3 id="Elasticsearch-在-docker-和-CentOS-下的安装教程"><a href="#Elasticsearch-在-docker-和-CentOS-下的安装教程" class="headerlink" title="Elasticsearch 在 docker 和 CentOS 下的安装教程"></a>Elasticsearch 在 docker 和 CentOS 下的安装教程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">sudo docker pull docker.elastic.co/elasticsearch/elasticsearch:<span class="number">7.3</span><span class="number">.1</span></span><br><span class="line"></span><br><span class="line">sudo docker run -p <span class="number">9200</span>:<span class="number">9200</span> -p <span class="number">9300</span>:<span class="number">9300</span> -e <span class="string">"discovery.type=single-node"</span> docker.elastic.co/elasticsearch/elasticsearch:<span class="number">7.3</span><span class="number">.1</span></span><br><span class="line"></span><br><span class="line">sudo docker run -itd -p <span class="number">9200</span>:<span class="number">9200</span> -p <span class="number">9300</span>:<span class="number">9300</span> -e <span class="string">"discovery.type=single-node"</span> docker.elastic.co/elasticsearch/elasticsearch:<span class="number">7.3</span><span class="number">.1</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/33404</span></span><br></pre></td></tr></table></figure>
<h3 id="wget-命令提示-“use-‘–no-check-certificate"><a href="#wget-命令提示-“use-‘–no-check-certificate" class="headerlink" title="wget 命令提示 “use ‘–no-check-certificate"></a>wget 命令提示 “use ‘–no-check-certificate</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">php -r <span class="string">"print_r(openssl_get_cert_locations());"</span></span><br><span class="line">可以看到证书的默认位置在 /etc/pki/tls/cert.pem，这是在安装 Apache 时自动生成的证书文件。如果你的目录里没有证书文件，使用下面的命令下载一个：</span><br><span class="line"></span><br><span class="line">$wget -c https:<span class="comment">//curl.haxx.se/ca/cacert.pem  /tmp --no-check-certificate</span></span><br><span class="line">因为我系统上本来就有一个证书文件了，为了不影响原来的，我将新的证书文件下载到 /tmp 目录中。然后设置以下环境变量，使证书只在当前会话生效：</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> SSL_CERT_FILE=<span class="regexp">/tmp/</span>cacert.pem</span><br><span class="line">https:<span class="comment">//learnku.com/articles/33549</span></span><br></pre></td></tr></table></figure>
<h3 id="docker"><a href="#docker" class="headerlink" title="docker"></a>docker</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">如果我们想在一台电脑上搭建各种开发环境：lnmp 环境，java 环境，nodejs，redis 集群，python 开发环境。显然，这些多的开发环境，如果集中在一台机器上构建，会让系统显得复杂，可能还会出现各种版本或依赖之间的不兼容。如果能将这些开发环境都独立开来，各个环境互相独立隔离，但又能互相通讯交互，相当于每个环境都是一个容器，这些容器可以独立提供服务，也能通信交互。</span><br><span class="line"></span><br><span class="line">docker 就是这样的容器技术。</span><br><span class="line"></span><br><span class="line">用官方术语描述 docker: Docker 是基于 Go 语言实现的开源容器项目，有效地将由单个操作系统管理的资源划分到孤立的组中，以更好地在孤立的组之间平衡有冲突的资源使用需求。</span><br><span class="line"></span><br><span class="line">通俗地理解：docker 能让你在一台物理机上构建出很多个轻量极的开发环境。</span><br><span class="line">https:<span class="comment">//learnku.com/articles/33670#reply108346</span></span><br></pre></td></tr></table></figure>
<h3 id="xargs-命令"><a href="#xargs-命令" class="headerlink" title="xargs 命令"></a>xargs 命令</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line">echo命令就不接受管道传参。</span><br><span class="line"></span><br><span class="line">$ echo <span class="string">"hello world"</span> | echo</span><br><span class="line">xargs命令的作用，是将标准输入转为命令行参数</span><br><span class="line">$ echo <span class="string">"hello world"</span> | xargs echo</span><br><span class="line">hello world</span><br><span class="line">$ echo <span class="string">"one two three"</span> | xargs mkdir</span><br><span class="line"></span><br><span class="line">$ xargs</span><br><span class="line"># 等同于</span><br><span class="line">$ xargs echo</span><br><span class="line">-d参数可以更改分隔符。</span><br><span class="line"></span><br><span class="line">$ echo -e <span class="string">"a\tb\tc"</span> | xargs -d <span class="string">"\t"</span> echo</span><br><span class="line">a b c</span><br><span class="line"></span><br><span class="line">$ echo <span class="string">'one two three'</span> | xargs -p touch</span><br><span class="line">touch one two three ?...</span><br><span class="line">上面的命令执行以后，会打印出最终要执行的命令，让用户确认。用户输入y以后（大小写皆可），才会真正执行。</span><br><span class="line">xargs特别适合find命令。有些命令（比如rm）一旦参数过多会报错<span class="string">"参数列表过长"</span>，而无法执行，改用xargs就没有这个问题，因为它对每个参数执行一次命令。</span><br><span class="line"></span><br><span class="line">$ find . -name <span class="string">"*.txt"</span> | xargs grep <span class="string">"abc"</span></span><br><span class="line">上面命令找出所有 TXT 文件以后，对每个文件搜索一次是否包含字符串abc</span><br><span class="line">http:<span class="comment">//www.ruanyifeng.com/blog/2019/08/xargs-tutorial.html</span></span><br></pre></td></tr></table></figure>
<h3 id="禁用-eval-函数"><a href="#禁用-eval-函数" class="headerlink" title="禁用 eval 函数"></a>禁用 eval 函数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">在 /etc/bashrc 里加入</span><br><span class="line">alias <span class="built_in">eval</span> = <span class="string">'echo'</span></span><br></pre></td></tr></table></figure>
<h3 id="find-模拟-tree"><a href="#find-模拟-tree" class="headerlink" title="find 模拟 tree"></a>find 模拟 tree</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ find . -print | sed -e <span class="string">``</span><span class="string">'s;[^/]*/;|____;g;s;____|; |;g'</span></span><br></pre></td></tr></table></figure>
<h3 id="Shell-命令组合"><a href="#Shell-命令组合" class="headerlink" title="Shell 命令组合"></a>Shell 命令组合</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">统计独立 IP 数量 awk <span class="string">'&#123;print $1&#125;'</span> access.log | sort -n | uniq | wc -l</span><br><span class="line">查看某一时间段的 IP 访问量 grep <span class="string">"05/Apr/2019:0[1-9]"</span> access.log | awk <span class="string">'&#123;print $1&#125;'</span> | sort | uniq -c| sort -nr | wc -l</span><br><span class="line">查看访问最频繁的前 <span class="number">100</span> 个 IP awk <span class="string">'&#123;print $1&#125;'</span> access.log | sort -n | uniq -c | sort -rn | head -n <span class="number">100</span></span><br><span class="line">访问 <span class="number">100</span> 次以上的 IP awk <span class="string">'&#123;print $1&#125;'</span> access.log | sort -n | uniq -c | awk <span class="string">'&#123;if($1 &gt; 100) print $0&#125;'</span> | sort -rn</span><br><span class="line">查询某个 IP 的详细访问情况，按访问频率排序 grep <span class="string">'127.0.0.1'</span> access.log | awk <span class="string">'&#123;print $7&#125;'</span> | sort | uniq -c | sort -rn | head -n <span class="number">100</span></span><br></pre></td></tr></table></figure>
<h3 id="Crontab-定时任务执行时的环境变量问题"><a href="#Crontab-定时任务执行时的环境变量问题" class="headerlink" title="Crontab 定时任务执行时的环境变量问题"></a>Crontab 定时任务执行时的环境变量问题</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">不是在 root 用户下安装的 scrapy，是在 crawl 用户下，然后一开始没注意，应该是用 root 用户配置的定时任务，导致定时任务找不到 scrapy，这个可以理解。但是当我在 crawl 用户下，重新配置了爬虫，发现还是报同样的错误。</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line">crontab -l  # 通过这个命令，可以查看当前用户下的定时任务</span><br><span class="line">解决办法</span><br><span class="line"></span><br><span class="line">后来经过查阅得知，crontab 有自己的环境变量配置，在 /etc/crontab 文件中，并不会自动加载当前用户的环境变量。所以在执行命令之前，应该先配置好环境变量。</span><br><span class="line"></span><br><span class="line">所以在 crontab 用户下，执行命令前先载入环境变量，如下。</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"><span class="number">00</span> <span class="number">10</span> * * * source $HOME/.bash_profile &amp;&amp; $HOME/path/to/script;sh /home/crawl/exec_aqi.sh &amp;  &gt; <span class="regexp">/dev/</span><span class="literal">null</span> <span class="number">2</span>&gt;&amp;</span><br><span class="line">如果直接修改 /etc/crontab 文件</span><br><span class="line">SHELL=<span class="regexp">/bin/</span>bash</span><br><span class="line">PATH=<span class="regexp">/sbin:/</span>bin:<span class="regexp">/usr/</span>sbin:<span class="regexp">/usr/</span>bin</span><br><span class="line">MAILTO=root</span><br><span class="line"><span class="number">00</span> <span class="number">10</span> * * * crawl sh /home/crawl/exec_aqi.sh &amp;</span><br><span class="line">https:<span class="comment">//zcdll.github.io/2018/01/30/own-crontab/</span></span><br></pre></td></tr></table></figure>
<h3 id="终端技巧大集合"><a href="#终端技巧大集合" class="headerlink" title="终端技巧大集合"></a>终端技巧大集合</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"># ‘&#123;&#125;’ 可用于匹配多个模式的文件名 </span><br><span class="line">ls &#123;*.sh,*.py&#125;   #列出所有.sh和.py文件</span><br><span class="line">筛选匹配前后返回的行（例如 “bbo”）</span><br><span class="line"></span><br><span class="line"># return also 3 lines after match</span><br><span class="line">grep -A <span class="number">3</span> <span class="string">'bbo'</span></span><br><span class="line"></span><br><span class="line"># return also 3 lines before match</span><br><span class="line">grep -B <span class="number">3</span> <span class="string">'bbo'</span></span><br><span class="line"></span><br><span class="line"># return also 3 lines before and after match</span><br><span class="line">grep -C <span class="number">3</span> <span class="string">'bbo'</span></span><br><span class="line">删除前 <span class="number">100</span> 行（删除第 <span class="number">1</span><span class="number">-100</span> 行）</span><br><span class="line"></span><br><span class="line">sed <span class="number">1</span>,<span class="number">100</span>d filename</span><br><span class="line">删除带字符串的行 (例如： bbo)</span><br><span class="line"></span><br><span class="line">sed <span class="string">"/bbo/d"</span> filename</span><br><span class="line">- <span class="keyword">case</span> insensitive:</span><br><span class="line">sed <span class="string">"/bbo/Id"</span> filename</span><br><span class="line">删除空行</span><br><span class="line"></span><br><span class="line">sed <span class="string">'/^\s*$/d'</span></span><br><span class="line"></span><br><span class="line"># 或</span><br><span class="line"></span><br><span class="line">sed <span class="string">'/^$/d'</span></span><br><span class="line">查找且删除</span><br><span class="line"></span><br><span class="line">find . -name <span class="string">"*.html"</span>|xargs rm</span><br><span class="line"></span><br><span class="line"># when using a backtick</span><br><span class="line">rm <span class="string">`find . -name "*.html"`</span></span><br><span class="line">https:<span class="comment">//learnku.com/laravel/t/35317#replies</span></span><br></pre></td></tr></table></figure>
<h3 id="网络知识之-IP-与子网掩码"><a href="#网络知识之-IP-与子网掩码" class="headerlink" title="网络知识之 IP 与子网掩码"></a>网络知识之 IP 与子网掩码</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line">IP 地址是一种在 Internet 上的给主机编址的方式，也称为网际协议地址。IP 地址是 IP 协议提供的一种统一的地址格式，它为互联网上的每一个网络和每一台主机分配一个逻辑地址，以此来屏蔽物理地址的差异。常见的 IP 地址，分为 IPv4 与 IPv6 两大类。主要介绍的是 IPv4 这一类。 IP 地址是一个 <span class="number">32</span> 位的二进制数，但为了方便记忆，通常被分割为 <span class="number">4</span> 个 <span class="string">"8 位二进制数"</span>，并且用 <span class="string">"点分十进制"</span> 表示为 a.b.c.d 的形式，其中 a,b,c,d 都是 <span class="number">0</span>~<span class="number">255</span> 之间的十进制整数。</span><br><span class="line"></span><br><span class="line">IP 地址分为五类，各类可容纳的地址数目不同：</span><br><span class="line"></span><br><span class="line">A 类保留给政府机构（<span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span> 到 <span class="number">127.255</span><span class="number">.255</span><span class="number">.255</span>）</span><br><span class="line"></span><br><span class="line">B 类分配给中等规模的公司（<span class="number">128.0</span><span class="number">.0</span><span class="number">.0</span> 到 <span class="number">191.255</span><span class="number">.255</span><span class="number">.255</span>）</span><br><span class="line"></span><br><span class="line">C 类分配给任何需要的人（<span class="number">192.0</span><span class="number">.0</span><span class="number">.0</span> 到 <span class="number">223.255</span><span class="number">.255</span><span class="number">.255</span>）</span><br><span class="line"></span><br><span class="line">D 类用于组播（<span class="number">224.0</span><span class="number">.0</span><span class="number">.0</span>--<span class="number">-239.255</span><span class="number">.255</span><span class="number">.255</span>）</span><br><span class="line"></span><br><span class="line">E 类用于实验（<span class="number">240.0</span><span class="number">.0</span><span class="number">.0</span>--<span class="number">-247.255</span><span class="number">.255</span><span class="number">.255</span>）</span><br><span class="line"></span><br><span class="line">A、B、C 三类中 IP 地址 = 网络地址 + 主机地址，而 D、E 两类不区分网络地址和主机地址</span><br><span class="line"></span><br><span class="line">特殊说明：</span><br><span class="line"></span><br><span class="line">（<span class="number">1</span>）A 类中的 <span class="number">10.</span>X.X.X 是私有地址；<span class="number">127.</span>X.X.X 是保留地址</span><br><span class="line"></span><br><span class="line">（<span class="number">2</span>）B 类中的 <span class="number">172.16</span><span class="number">.0</span><span class="number">.0</span>~<span class="number">172.31</span><span class="number">.255</span><span class="number">.255</span> 是私有地址</span><br><span class="line"></span><br><span class="line">（<span class="number">3</span>）C 类中的 <span class="number">192.168</span>.X.X 是私有地址</span><br><span class="line">网络地址可以简单理解我们平时常说的网段</span><br><span class="line"></span><br><span class="line">主机地址则是在这个网段中不同设备的地址</span><br><span class="line">子网掩码只有一个作用，就是将一个 IP 地址划分成网络地址和主机地址两部分。</span><br><span class="line"></span><br><span class="line">（常见的掩码是由一连串 <span class="number">1</span> + 一连串 <span class="number">0</span> 构成的，不过看网上资料也说 <span class="number">1</span> 和 <span class="number">0</span> 交替也是可以的）</span><br><span class="line"></span><br><span class="line">默认分配的子网掩码每段只有 <span class="number">255</span> 或 <span class="number">0</span></span><br><span class="line"></span><br><span class="line">A 类的默认子网掩码　<span class="number">255.0</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line">B 类的默认子网掩码　<span class="number">255.255</span><span class="number">.0</span><span class="number">.0</span>　　</span><br><span class="line">C 类的默认子网掩码　<span class="number">255.255</span><span class="number">.255</span><span class="number">.0</span></span><br><span class="line">子网掩码与 IP 地址一样是 <span class="number">32</span> 位地址，然后将 IP 地址与子网掩码进行与运算即可得到网络地址。</span><br><span class="line"></span><br><span class="line">例：</span><br><span class="line"></span><br><span class="line">IP地址为<span class="number">192.168</span><span class="number">.10</span><span class="number">.2</span>，子网掩码为<span class="number">255.255</span><span class="number">.255</span><span class="number">.240</span>。</span><br><span class="line">先将十进制转换成二进制：</span><br><span class="line">IP地址：  <span class="number">11000000</span> <span class="number">10101000</span> <span class="number">00001010</span> <span class="number">00000010</span></span><br><span class="line">子网掩码： <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11110000</span></span><br><span class="line">进行与运算：－－－－－－－－－－－－－－－－－－－－－－－－－－</span><br><span class="line">          <span class="number">11000000</span> <span class="number">10101000</span> <span class="number">00001010</span> <span class="number">00000000</span></span><br><span class="line">则可得其网络标识为<span class="number">192.168</span><span class="number">.10</span><span class="number">.0</span>，主机标识为<span class="number">2</span>。</span><br><span class="line"><span class="number">3.</span> 掩码的不同表示形式</span><br><span class="line"></span><br><span class="line">已经说过了子网掩码也是 <span class="number">32</span> 位的地址，那么开头的 <span class="number">25</span> 怎么转化呢？</span><br><span class="line"></span><br><span class="line"><span class="number">25</span> 的意思是网络号为 <span class="number">25</span>，就代表连续的 <span class="number">25</span> 个 <span class="number">1</span>，然后剩下的用 <span class="number">0</span> 补齐</span><br><span class="line"></span><br><span class="line">即 <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">11111111</span> <span class="number">10000000</span></span><br><span class="line"></span><br><span class="line"><span class="number">4.</span> 包含的其他信息</span><br><span class="line"></span><br><span class="line">还是以这个信息为例：XX.XX.XX<span class="number">.128</span>/<span class="number">25</span>，我们还可以拿到什么信息呢？</span><br><span class="line"></span><br><span class="line">（<span class="number">1</span>）主机号：主机号 + 网络号 = <span class="number">32</span>，<span class="number">32</span><span class="number">-25</span>=<span class="number">7</span></span><br><span class="line"></span><br><span class="line">（<span class="number">2</span>）网络地址：当 <span class="number">7</span> 位主机号全为 <span class="number">0</span>，也就是 XX.XX.XX<span class="number">.128</span></span><br><span class="line"></span><br><span class="line">（<span class="number">3</span>）广播地址：当 <span class="number">7</span> 位主机号全为 <span class="number">1</span>，也就是 XX.XX.XX<span class="number">.255</span></span><br><span class="line"></span><br><span class="line">（<span class="number">4</span>）可用地址数量：<span class="number">7</span> 位主机号有 <span class="number">2</span>^<span class="number">7</span> 种结果，但是要去掉网络地址和广播地址，即：<span class="number">2</span>^<span class="number">7</span><span class="number">-2</span>=<span class="number">126</span> (这个也就是运维所说的一百多个 ip)https:<span class="comment">//learnku.com/articles/35666</span></span><br></pre></td></tr></table></figure>
<h3 id="ssh免密登录漏洞"><a href="#ssh免密登录漏洞" class="headerlink" title="ssh免密登录漏洞"></a>ssh免密登录漏洞</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">[root@localhost ~]# ll .ssh/</span><br><span class="line">total <span class="number">42944</span></span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root <span class="number">43918390</span> Nov  <span class="number">6</span>  <span class="number">2017</span> authorized_keys</span><br><span class="line">-rw-r--r-- <span class="number">1</span> root root     <span class="number">3415</span> Apr <span class="number">26</span>  <span class="number">2019</span> known_hosts</span><br><span class="line">[root@localhost ~]# cat .ssh/known_hosts</span><br><span class="line">git.coding.net,<span class="number">221.193</span><span class="number">.246</span><span class="number">.6</span> ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDHOWdwLpkos2CLli6DFvQ36yQE6Pe/PtFp3XwyirfZCIoGWnedaWI8zkJWVCs0wgOB9/urFepTDfV2wN49KGy1sl2/CCDEH2K/zeoEAZlTcBrhU17bwg1yMHCyJ7IM+zdLzItDEKYjgoWqVdUGK1dXQQlwt7GP4W7HqffelQQoVxOMoZ5N50MzD+nvV4y8iq0KwDQNy62iU4hui9ajCSVUDLu/<span class="number">06</span>ucd5IojSI9keRIYAXvQf52TJ5EbvoBggp9RhjuWNEG8IhnPP6rzPS11Ocmwg/Hs</span><br><span class="line">打开 vi authorized_keys 并没有任何东西。然后我顺带把其它 /root/.ssh/ 下的四个文件都翻了一遍。</span><br><span class="line">才发现 known_hosts 文件中多了两个 IP 地址为新加坡的 ssh key  https:<span class="comment">//learnku.com/articles/35888</span></span><br></pre></td></tr></table></figure>
<h3 id="crontab-指定用户"><a href="#crontab-指定用户" class="headerlink" title="crontab 指定用户"></a>crontab 指定用户</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line">直接在 /etc/crontab 中编辑定时任务即可，加上用户名</span><br><span class="line">SHELL=<span class="regexp">/bin/</span>sh</span><br><span class="line">PATH=<span class="regexp">/usr/</span>local/sbin:<span class="regexp">/usr/</span>local/bin:<span class="regexp">/sbin:/</span>bin:<span class="regexp">/usr/</span>sbin:<span class="regexp">/usr/</span>bin</span><br><span class="line"></span><br><span class="line"># Example of job definition:</span><br><span class="line"># .---------------- minute (0 - 59)</span><br><span class="line"># |  .------------- hour (0 - 23)</span><br><span class="line"># |  |  .---------- day of month (1 - 31)</span><br><span class="line"># |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...</span><br><span class="line"># |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat</span><br><span class="line"># |  |  |  |  |</span><br><span class="line"># *  *  *  *  * user-name command to be executed</span><br><span class="line"><span class="number">17</span> *    * * *   root    cd / &amp;&amp; run-parts --report /etc/cron.hourly</span><br><span class="line"><span class="number">25</span> <span class="number">6</span>    * * *   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.daily )</span><br><span class="line"><span class="number">47</span> <span class="number">6</span>    * * <span class="number">7</span>   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.weekly )</span><br><span class="line"><span class="number">52</span> <span class="number">6</span>    <span class="number">1</span> * *   root    test -x /usr/sbin/anacron || ( cd / &amp;&amp; run-parts --report /etc/cron.monthly )</span><br><span class="line">#</span><br><span class="line"></span><br><span class="line"># cron</span><br><span class="line">* * * * *  www-data flock /tmp/flock1.lock -c <span class="string">'timeout 200 /usr/local/bin/php /var/www/html/laravel/artisan command &gt;&gt; /home/log/laravel.log 2&gt;&amp;1'</span></span><br><span class="line">flock 用来防止重复执行，起到原子锁作用</span><br><span class="line">                                                                                                                                                  timeout 表示这个脚本执行过长，咱就干死它，可以有效避免各种循环或长时间占用问题</span><br><span class="line">https:<span class="comment">//learnku.com/articles/35948</span></span><br><span class="line"></span><br><span class="line">* * * * * flock -xn /tmp/test.lock -c <span class="string">"timeout 200 php /home/app/email.php &gt;&gt; /home/log/test.log 2&gt;&amp;1"</span> </span><br><span class="line">想 <span class="number">10</span>s 执行一次怎么办？</span><br><span class="line"></span><br><span class="line">* * * * * php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span></span><br><span class="line">* * * * * ( sleep <span class="number">10</span> ; php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> )</span><br><span class="line">* * * * * ( sleep <span class="number">20</span> ; php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> )</span><br><span class="line">* * * * * ( sleep <span class="number">30</span> ; php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> )</span><br><span class="line">* * * * * ( sleep <span class="number">40</span> ; php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> )</span><br><span class="line">* * * * * ( sleep <span class="number">50</span> ; php /home/app/email.php &gt;&gt; <span class="regexp">/home/</span>log/test.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> )</span><br></pre></td></tr></table></figure>
<h3 id="gt-gt-gt"><a href="#gt-gt-gt" class="headerlink" title="&gt;  &gt;&gt;"></a>&gt;  &gt;&gt;</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">&gt; 表示覆盖追加</span><br><span class="line">&gt;&gt; 表示尾部追加</span><br><span class="line">这两个管道操作符，在执行期间发生错误时，是不会将错误输出写入后面的「文件」中的。</span><br><span class="line">在 Linux 系统中 <span class="number">0</span>、<span class="number">1</span>、<span class="number">2</span> 分别表示不同的设备类型，其中</span><br><span class="line"></span><br><span class="line"><span class="number">0</span> 标准输入设备，指键盘</span><br><span class="line"><span class="number">1</span> 标准正确输出设备</span><br><span class="line"><span class="number">2</span> 标准错误输出设备</span><br><span class="line">php artisan command &gt;&gt; <span class="regexp">/home/</span>log/laravel.log <span class="number">2</span>&gt;&amp;<span class="number">1</span><span class="string">'</span></span><br><span class="line"><span class="string">上面命令的意思是将 php artisan command 的 标准正确输出 重定向到 laravel.log 文件。</span></span><br><span class="line"><span class="string">而后面的 2&gt;&amp;1 是表示将标注错误输出重定向到标准正确输出。</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">从而达到错误输出和正确输出都记录在 laravel.log 文件中。</span></span><br></pre></td></tr></table></figure>
<h3 id="内网穿透"><a href="#内网穿透" class="headerlink" title="内网穿透"></a>内网穿透</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">https:<span class="comment">//serveo.net/</span></span><br><span class="line">λ ssh -R <span class="number">80</span>:localhost:<span class="number">3000</span> serveo.net</span><br><span class="line">Forwarding HTTP traffic <span class="keyword">from</span> https:<span class="comment">//habeo.serveo.net</span></span><br><span class="line">Press g to start a GUI session and ctrl-c to quit.</span><br></pre></td></tr></table></figure>
<h3 id="ab-压力测试"><a href="#ab-压力测试" class="headerlink" title="ab 压力测试"></a>ab 压力测试</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">ab -n <span class="number">2000</span> -c <span class="number">1000</span> http:<span class="comment">//www.xxx.com/index.php</span></span><br><span class="line">需要调整内核参数以支持端口重用</span><br><span class="line">假如我现在使用的是 Linux 服务器，找到如下文件</span><br><span class="line">sudo vim /etc/sysctl.conf</span><br><span class="line">添加如下内容</span><br><span class="line"></span><br><span class="line">net.ipv4.tcp_syncookies = <span class="number">1</span></span><br><span class="line">net.ipv4.tcp_tw_reuse = <span class="number">1</span></span><br><span class="line">net.ipv4.tcp_tw_recycle = <span class="number">1</span></span><br><span class="line">net.ipv4.tcp_fin_timeout = <span class="number">30</span></span><br><span class="line">kernel.printk = <span class="number">7</span> <span class="number">4</span> <span class="number">1</span> <span class="number">7</span></span><br><span class="line">运行 sudo sysctl –p 生效</span><br><span class="line">https:<span class="comment">//learnku.com/articles/4765/simple-primary-stress-test</span></span><br></pre></td></tr></table></figure>
<h3 id="https-证书注册工具"><a href="#https-证书注册工具" class="headerlink" title="https 证书注册工具"></a>https 证书注册工具</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">apt-get install certbot python-certbot-nginx</span><br><span class="line">certbot --nginx</span><br><span class="line">certbot renew --dry-run</span><br><span class="line"></span><br><span class="line">https://certbot.eff.org/</span><br></pre></td></tr></table></figure>
<h3 id="linux卡顿怎么排查"><a href="#linux卡顿怎么排查" class="headerlink" title="linux卡顿怎么排查"></a>linux卡顿怎么排查</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">ps -ef | grep php | awk <span class="string">'&#123;print $2&#125;'</span> | xargs kill <span class="number">-9</span></span><br><span class="line">查看内存使用状况：free -g</span><br><span class="line">查看磁盘使用状况：df -h</span><br><span class="line">查看磁盘I/O使用：iostat -dx</span><br><span class="line">查看CPU使用：top</span><br><span class="line"></span><br><span class="line">awk <span class="string">'条件类型 1&#123;动作1&#125; 条件类型2&#123;动作2&#125; ...'</span> filename</span><br><span class="line">awk后面接两个引号并加上大括号来设置想要对数据进行的处理动作。https:<span class="comment">//tsmliyun.github.io/linux/%E4%B8%80%E6%AC%A1%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E9%85%8D%E7%BD%AE%E9%94%99%E8%AF%AF%E5%BC%95%E5%8F%91%E7%9A%84%E6%80%9D%E8%80%83/</span></span><br></pre></td></tr></table></figure>
<h3 id="docker-1"><a href="#docker-1" class="headerlink" title="docker"></a>docker</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">curl -L <span class="string">"https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)"</span> -o /usr/local/bin/docker-compose</span><br><span class="line">chmod +x /usr/local/bin/docker-compose</span><br><span class="line">[root@VM_0_11_centos html]# docker-compose version</span><br><span class="line">docker-compose version <span class="number">1.24</span><span class="number">.1</span>, build <span class="number">4667896</span>b</span><br><span class="line">docker-py version: <span class="number">3.7</span><span class="number">.3</span></span><br><span class="line">CPython version: <span class="number">3.6</span><span class="number">.8</span></span><br><span class="line">OpenSSL version: OpenSSL <span class="number">1.1</span><span class="number">.0</span>j  <span class="number">20</span> Nov <span class="number">2018</span></span><br><span class="line"> docker pull gogs/gogs</span><br><span class="line"> [root@VM_0_11_centos html]# docker start gogs</span><br><span class="line"> gogs</span><br><span class="line"> [root@VM_0_11_centos html]# docker ps</span><br><span class="line"> CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS</span><br><span class="line">   PORTS                                            NAMES</span><br><span class="line"> <span class="number">1</span>bd82406bba2        gogs/gogs           <span class="string">"/app/gogs/docker/st…"</span>   <span class="number">7</span> hours ago         Up <span class="number">7</span> hours</span><br><span class="line">   <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:<span class="number">10022</span>-&gt;<span class="number">22</span>/tcp, <span class="number">0.0</span><span class="number">.0</span><span class="number">.0</span>:<span class="number">10080</span>-&gt;<span class="number">3000</span>/tcp   gogs</span><br><span class="line">   </span><br><span class="line">   https:<span class="comment">//learnku.com/articles/34941</span></span><br></pre></td></tr></table></figure>
<h3 id="cURL-error-28-Resolving-timed-out-after-5515-milliseconds"><a href="#cURL-error-28-Resolving-timed-out-after-5515-milliseconds" class="headerlink" title="cURL error 28: Resolving timed out after 5515 milliseconds"></a>cURL error 28: Resolving timed out after 5515 milliseconds</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line">$ cat /etc/resolv.conf</span><br><span class="line">不要手动修改 /etc/resolv.conf，因为此文件动态生成的，先看下文件：</span><br><span class="line"></span><br><span class="line">$ cat /etc/network/interfaces</span><br><span class="line">最后一行的 dns-nameservers 是我们的目标，开始修改：</span><br><span class="line"></span><br><span class="line">$ vi /etc/network/interfaces</span><br><span class="line">比较知名的公共 DNS 可以请问这里查看 https:<span class="comment">//www.ip.cn/dns.html ，这里选择 114 和 阿里的 DNS:</span></span><br><span class="line"></span><br><span class="line">auto lo</span><br><span class="line">iface lo inet loopback</span><br><span class="line">auto eth0</span><br><span class="line">iface eth0 inet <span class="keyword">static</span></span><br><span class="line">address <span class="number">10.</span>x<span class="number">.23</span>.xxx</span><br><span class="line">netmask <span class="number">255.255</span><span class="number">.0</span><span class="number">.0</span></span><br><span class="line">gateway <span class="number">10.</span>x<span class="number">.0</span>.x</span><br><span class="line">mtu <span class="number">1454</span></span><br><span class="line">dns-nameservers <span class="number">114.114</span><span class="number">.114</span><span class="number">.114</span> <span class="number">114.114</span><span class="number">.115</span><span class="number">.115</span> <span class="number">223.5</span><span class="number">.5</span><span class="number">.5</span></span><br><span class="line">最后面 dns-nameservers 是 DNS ，修改最后一行即可，修改完成后：</span><br><span class="line"></span><br><span class="line">$ ifdown eth0 &amp;&amp; sudo ifup eth0</span><br><span class="line">重启成功后，确认是否应用上：</span><br><span class="line"></span><br><span class="line">$ cat /etc/resolv.conf</span><br><span class="line">可以看到输出：</span><br><span class="line"></span><br><span class="line"># Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)</span><br><span class="line">#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN</span><br><span class="line">nameserver <span class="number">114.114</span><span class="number">.114</span><span class="number">.114</span></span><br><span class="line">nameserver <span class="number">114.114</span><span class="number">.115</span><span class="number">.115</span></span><br><span class="line">nameserver <span class="number">223.5</span><span class="number">.5</span><span class="number">.5</span></span><br><span class="line">https:<span class="comment">//learnku.com/ubuntu/t/32705</span></span><br></pre></td></tr></table></figure>
<h3 id="内存消耗最大的进程"><a href="#内存消耗最大的进程" class="headerlink" title="内存消耗最大的进程"></a>内存消耗最大的进程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">[root@VM_0_11_centos html]# ps aux --sort -rss | head</span><br><span class="line">USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND</span><br><span class="line">root      <span class="number">3367</span>  <span class="number">0.0</span>  <span class="number">3.9</span> <span class="number">523176</span> <span class="number">74068</span> ?        Ssl  Nov14   <span class="number">0</span>:<span class="number">53</span> /usr/bin/dockerd -H fd:<span class="comment">// --containerd</span></span><br><span class="line">=<span class="regexp">/run/</span>containerd/containerd.sock</span><br><span class="line">ps -eo pid,ppid,%mem,%cpu,cmd --sort=-%mem | head</span><br><span class="line">如果你只想查看命令名称而不是命令的绝对路径，请使用下面的 ps 命令格式。</span><br><span class="line"></span><br><span class="line"># ps -eo pid,ppid,%mem,%cpu,comm --sort=-%mem | head</span><br><span class="line"># top -c -b -o +%MEM | head -n 20 | tail -15</span><br><span class="line">如果你只想查看命令名称而不是命令的绝对路径，请使用下面的 top 命令格式。</span><br><span class="line"></span><br><span class="line"># top -b -o +%MEM | head -n 20 | tail -15</span><br><span class="line">https:<span class="comment">//cn.v2ex.com/t/619291#</span></span><br></pre></td></tr></table></figure>
<h3 id="Nginx-负载均衡"><a href="#Nginx-负载均衡" class="headerlink" title="Nginx 负载均衡"></a>Nginx 负载均衡</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line">语法: upstream name &#123; ... &#125; </span><br><span class="line">默认值: —</span><br><span class="line">上下文: http</span><br><span class="line"></span><br><span class="line">upstream 指令当中包含server指令</span><br><span class="line">语法: server address [parameters]; </span><br><span class="line">上下文: upstream</span><br><span class="line"></span><br><span class="line">例子:</span><br><span class="line">upstream backend &#123;</span><br><span class="line">    server backend1.example.com:<span class="number">8081</span> weight=<span class="number">4</span> max_fails=<span class="number">2</span> fail_timeout=<span class="number">30</span>s; </span><br><span class="line">    server backend2.example.com:<span class="number">8080</span> weight=<span class="number">1</span>;</span><br><span class="line">&#125;</span><br><span class="line">server &#123; </span><br><span class="line">    location / &#123;</span><br><span class="line">        proxy_pass http:<span class="comment">//backend; </span></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">参数说明:</span><br><span class="line">weight=number 设定服务器的权重，默认是<span class="number">1</span>，权重越大被访问机会越大，可以根据机器的配置情况来配置。</span><br><span class="line"></span><br><span class="line">max_fails=number 设定Nginx与服务器通信的尝试失败的次数。在fail_timeout参数定义的时间段内，如果失败的次数达到此值，Nginx就认为服务器不 可用。在下一个fail_timeout时间段，服务器不会再被尝试。 失败的尝试次数默认是<span class="number">1</span>。</span><br><span class="line"></span><br><span class="line">默认配置时，http_404状态不被认为是失败的尝试。 可以通过指令proxy_next_upstream 和memcached_next_upstream来配置什么是失败的尝试。</span><br><span class="line"></span><br><span class="line">fail_timeout=time</span><br><span class="line">统计失败尝试次数的时间段。在这段时间中，服务器失败次数达到指定的尝试次数，服务器就被认为不可用。默认情况下，该超时时间是<span class="number">10</span>秒。 </span><br><span class="line"></span><br><span class="line">backup</span><br><span class="line">标记为备用服务器。当主服务器不可用以后，请求会被传给这些服务器，配置这个指令可以实现故障转移。</span><br><span class="line"></span><br><span class="line">down 标记服务器永久不可用，可以跟ip_hash指令一起使用。</span><br><span class="line">https:<span class="comment">//learnku.com/articles/36737</span></span><br></pre></td></tr></table></figure>
<h3 id="Nginx-配置常用参数"><a href="#Nginx-配置常用参数" class="headerlink" title="Nginx 配置常用参数"></a>Nginx 配置常用参数</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br></pre></td><td class="code"><pre><span class="line"># 配置用户或者组，默认为nobody nobody。</span><br><span class="line">#user www www;  </span><br><span class="line"></span><br><span class="line"> #Nginx开启的worker进程数，建议为CPU的核数</span><br><span class="line">#worker_processes 2; </span><br><span class="line"></span><br><span class="line">#指定nginx进程运行文件存放地址</span><br><span class="line">#pid /nginx/pid/nginx.pid;</span><br><span class="line"></span><br><span class="line">#指定日志路径，级别。这个设置可以放入全局块、http块、server块，级别以此为：debug|info|notice|warn|error|crit|alert|emerg</span><br><span class="line">error_log log/error.log debug; </span><br><span class="line"></span><br><span class="line">#可以在任意地方使用include指令实现配置文件的包含，类似于apache中的include方法，可减少主配置文件长度。</span><br><span class="line">include vhosts<span class="comment">/*.conf;</span></span><br><span class="line"><span class="comment">事件模块</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">events &#123;</span></span><br><span class="line"><span class="comment">    #设置网路连接序列化，防止惊群现象发生，默认为on</span></span><br><span class="line"><span class="comment">    accept_mutex on; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #默认: 500ms 如果一个进程没有互斥锁，它将延迟至少多长时间。默认情况下，延迟是500ms 。</span></span><br><span class="line"><span class="comment">    accept_mutex_delay 100ms; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #设置一个进程是否同时接受多个网络连接，默认为off</span></span><br><span class="line"><span class="comment">    multi_accept on;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #事件驱动模型，select|poll|kqueue|epoll|resig|/dev/poll|eventport，不建议设置，nginx会自行选择</span></span><br><span class="line"><span class="comment">    #use epoll;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #最大连接数，默认为512</span></span><br><span class="line"><span class="comment">    worker_connections  1024;</span></span><br><span class="line"><span class="comment">&#125;</span></span><br><span class="line"><span class="comment">http 部分</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">http &#123;</span></span><br><span class="line"><span class="comment">    #文件扩展名与文件类型映射表</span></span><br><span class="line"><span class="comment">    include       mime.types;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    # 默认文件类型，默认为text/plain</span></span><br><span class="line"><span class="comment">    default_type  application/octet-stream; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #取消服务日志 </span></span><br><span class="line"><span class="comment">    #access_log off; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #允许sendfile方式传输文件，默认为off，可以在http块，server块，location块。</span></span><br><span class="line"><span class="comment">    sendfile on;   </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #每个进程每次调用传输数量不能大于设定的值，默认为0，即不设上限。</span></span><br><span class="line"><span class="comment">    sendfile_max_chunk 100k;  </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #连接超时时间，默认为75s，可以在http，server，location块。</span></span><br><span class="line"><span class="comment">    keepalive_timeout 65;  </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #开启gzip资源压缩</span></span><br><span class="line"><span class="comment">    gzip  on; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    # 负载均衡，详细可看了一篇文章：https://learnku.com/articles/36737</span></span><br><span class="line"><span class="comment">    upstream blog &#123;   </span></span><br><span class="line"><span class="comment">        server 192.167.20.19:8081;</span></span><br><span class="line"><span class="comment">        server 192.168.10.121:8080 weight=5;</span></span><br><span class="line"><span class="comment">    &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #设定请求缓冲</span></span><br><span class="line"><span class="comment">    client_header_buffer_size    128k;</span></span><br><span class="line"><span class="comment">    large_client_header_buffers  4 128k;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    #上传文件的大小限制  默认1m</span></span><br><span class="line"><span class="comment">    client_max_body_size 8m;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">    server &#123;</span></span><br><span class="line"><span class="comment">        #单连接请求上限次数。</span></span><br><span class="line"><span class="comment">        keepalive_requests 120;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        #监听端口</span></span><br><span class="line"><span class="comment">        listen       80;   </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        #监听地址</span></span><br><span class="line"><span class="comment">        server_name  blog.13sai.com;  </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        #设定日志格式</span></span><br><span class="line"><span class="comment">        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '</span></span><br><span class="line"><span class="comment">                      '$status $body_bytes_sent "$http_referer" '</span></span><br><span class="line"><span class="comment">                      '"$http_user_agent" "$http_x_forwarded_for"';</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        access_log  /data/logs/access.log  main;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        # 根目录</span></span><br><span class="line"><span class="comment">        root /www/web/public; </span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        # 定义错误提示页面</span></span><br><span class="line"><span class="comment">        error_page   500 502 503 504 /50x.html;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        location /static/ &#123;</span></span><br><span class="line"><span class="comment">            #root与alias主要区别在于nginx如何解释location后面的uri，这会使两者分别以不同的方式将请求映射到服务器文件上。</span></span><br><span class="line"><span class="comment">            #root的处理结果是：root路径＋location路径</span></span><br><span class="line"><span class="comment">            #alias的处理结果是：使用alias路径替换location路径</span></span><br><span class="line"><span class="comment">            alias /www/static/;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">            #过期30天，静态文件不怎么更新，过期可以设大一点,如果频繁更新，则可以设置得小一点。</span></span><br><span class="line"><span class="comment">            expires 30d;</span></span><br><span class="line"><span class="comment">        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        # 处理php请求到fpm端口</span></span><br><span class="line"><span class="comment">        location ~ \.php$ &#123;</span></span><br><span class="line"><span class="comment">            fastcgi_pass   127.0.0.1:9000;</span></span><br><span class="line"><span class="comment">            fastcgi_index  index.php;</span></span><br><span class="line"><span class="comment">            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;</span></span><br><span class="line"><span class="comment">            include        fastcgi_params;</span></span><br><span class="line"><span class="comment">        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        location / &#123;</span></span><br><span class="line"><span class="comment">            proxy_set_header Host $host;</span></span><br><span class="line"><span class="comment">            proxy_set_header  X-Real-IP  $remote_addr;</span></span><br><span class="line"><span class="comment">            proxy_pass  http://blog;  #请求转向blog 定义的服务器列表 </span></span><br><span class="line"><span class="comment">        &#125;</span></span><br><span class="line"><span class="comment"></span></span><br><span class="line"><span class="comment">        #禁止访问文件</span></span><br><span class="line"><span class="comment">        location ~ /.git &#123;</span></span><br><span class="line"><span class="comment">            deny all;</span></span><br><span class="line"><span class="comment">            allow 127.0.0.1; #允许的ip </span></span><br><span class="line"><span class="comment">        &#125;</span></span><br><span class="line"><span class="comment">    &#125;</span></span><br><span class="line"><span class="comment">&#125; https://learnku.com/articles/36768</span></span><br></pre></td></tr></table></figure>
<h3 id="反向代理后如何获取真实客户端-IP"><a href="#反向代理后如何获取真实客户端-IP" class="headerlink" title="反向代理后如何获取真实客户端 IP"></a>反向代理后如何获取真实客户端 IP</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">location /api &#123; </span><br><span class="line">           rewrite  ^<span class="regexp">/api/</span>(.*)$ /api/$<span class="number">1</span> <span class="keyword">break</span>;</span><br><span class="line">           proxy_pass   https:<span class="comment">//***.*********.com;</span></span><br><span class="line">   &#125;</span><br><span class="line">   proxy_set_header X-Forwarded-For $remote_addr;</span><br><span class="line">   proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;</span><br><span class="line">   如果有报错</span><br><span class="line">   Starting nginx: nginx: [warn] could not build optimal proxy_headers_hash, you should increase either proxy_headers_hash_max_size: <span class="number">512</span> or proxy_headers_hash_bucket_size: <span class="number">64</span>; ignoring proxy_headers_hash_bucket_size</span><br><span class="line">   </span><br><span class="line">       nginx.conf 下的http 模块下设置</span><br><span class="line">       proxy_headers_hash_max_size <span class="number">51200</span>;</span><br><span class="line">       proxy_headers_hash_bucket_size <span class="number">6400</span>;</span><br><span class="line">   </span><br><span class="line">   <span class="number">3</span> 代码里面获取</span><br><span class="line">      $ip = $_SERVER[<span class="string">'HTTP_X_FORWARDED_FOR'</span>];</span><br><span class="line">   https:<span class="comment">//learnku.com/articles/36832</span></span><br></pre></td></tr></table></figure>
<h3 id="docker-入门"><a href="#docker-入门" class="headerlink" title="docker 入门"></a>docker 入门</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">Docker 是一个开源的应用容器引擎，让开发者可以打包他们的应用以及依赖包到一个可移植的镜像中，然后发布到任何流行的 Linux 或 Windows 机器上，也可以实现虚拟化。容器是完全使用沙箱机制，相互之间不会有任何接口。</span><br><span class="line">docker images -- 常看本地镜像</span><br><span class="line">docker ps -- 查看容器，默认只查看已启动的，加入 <span class="string">"-a"</span> 参数可以查看所有</span><br><span class="line">docker start|stop|rm|rmi -- 容器的相关操作，分别对应： 开启 | 停止 | 删除容器 | 删除镜像</span><br><span class="line">docker pull ubuntu</span><br><span class="line"></span><br><span class="line">docker run -itd --name test-ubuntu ubuntu</span><br><span class="line">docker exec -it test-ubuntu /bin/bash</span><br><span class="line">docker pull php:<span class="number">7.3</span><span class="number">.5</span>-fpm</span><br><span class="line">docker run -itd -p <span class="number">9001</span>:<span class="number">9000</span> -v /Users/admin/Site/php7<span class="number">.3</span><span class="number">.5</span>:<span class="regexp">/data --name php-test php:7.3.5-fpm</span></span><br><span class="line"><span class="regexp">docker exec -it php-test /</span>bin/bash</span><br><span class="line">vi /etc/nginx/config.d/php.conf</span><br><span class="line">server &#123;</span><br><span class="line">    # 监听端口</span><br><span class="line">    listen       <span class="number">8002</span>;</span><br><span class="line"></span><br><span class="line">    # 域名设定</span><br><span class="line">    server_name  <span class="number">122.51</span><span class="number">.155</span><span class="number">.172</span>;</span><br><span class="line"></span><br><span class="line">    root /usr/share/nginx/html/php/; # 该项要修改为你准备存放相关网页的路径，如果存在fast-cgi的root字段，这里貌似就没效果了</span><br><span class="line"></span><br><span class="line">    location / &#123;</span><br><span class="line"></span><br><span class="line">    index index.php index.html;</span><br><span class="line"></span><br><span class="line">    # 打开目录浏览功能，可以列出整个目录</span><br><span class="line"></span><br><span class="line">    autoindex on;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    #proxy the php scripts to php-fpm</span><br><span class="line"></span><br><span class="line">    location ~ \.php$ &#123;</span><br><span class="line">    # fastcgi配置</span><br><span class="line"></span><br><span class="line">    # 指定是否传递4xx和5xx错误信息到客户端</span><br><span class="line"></span><br><span class="line">    fastcgi_intercept_errors on;</span><br><span class="line"></span><br><span class="line">    # 指定FastCGI服务器监听端口与地址，可以是本机或者其它,这里是重点，需要指定php-fpm容器的端口和根目录</span><br><span class="line">    fastcgi_pass   <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9001</span>;</span><br><span class="line">    root /data;</span><br><span class="line">    fastcgi_index index.php;</span><br><span class="line">    include  fastcgi_params;</span><br><span class="line">    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br><span class="line">sysctemclt restart nginx </span><br><span class="line">vi /usr/share/nginx/html/php/inde.php </span><br><span class="line">访问http:<span class="comment">//122.51.155.172:8002/</span></span><br><span class="line">Dockerfile 是一个包含用于组合映像的命令的文本文档。可以使用在命令行中调用任何命令。 Docker 通过读取 Dockerfile 中的指令自动生成映像。</span><br><span class="line">FROM php:<span class="number">7.3</span><span class="number">.5</span>-fpm</span><br><span class="line">MAINTAINER liyan</span><br><span class="line"></span><br><span class="line">#安装环境系统命令</span><br><span class="line">RUN apt-get update &amp;&amp; apt-get install -y \</span><br><span class="line">vim \</span><br><span class="line">libssl-dev</span><br><span class="line"></span><br><span class="line">#安装PHP扩展</span><br><span class="line">RUN pecl install igbinary \</span><br><span class="line">redis<span class="number">-4.0</span><span class="number">.2</span> \</span><br><span class="line">swoole</span><br><span class="line"></span><br><span class="line">#配置php.ini</span><br><span class="line">RUN cp /usr/local/etc/php/php.ini-production /usr/local/etc/php/php.ini &amp;&amp; \</span><br><span class="line">ln -s /usr/local/etc/php/php.ini /etc/php.ini &amp;&amp; \</span><br><span class="line">echo <span class="string">"extension=igbinary.so\nextension=redis.so\nextension=swoole.so"</span> &gt;&gt; <span class="regexp">/etc/</span>php.ini</span><br><span class="line"></span><br><span class="line">EXPOSE <span class="number">9300</span></span><br><span class="line">VOLUME [<span class="string">"/data"</span>]</span><br><span class="line">WORKDIR /data</span><br><span class="line">https:<span class="comment">//learnku.com/articles/36739</span></span><br></pre></td></tr></table></figure>
<h3 id="忽略文件"><a href="#忽略文件" class="headerlink" title="忽略文件"></a>忽略文件</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">已经推送 push 过的文件，想在以后的提交时忽略此文件，即使本地已经修改过，而且不删除 Git 远程库中相应文件，后面的 Xml/config.xml 是要忽略的文件的路径，执行命令：</span><br><span class="line"></span><br><span class="line">git update-index --assume-unchanged Xml/config.xml  </span><br><span class="line">恢复忽略的文件，执行命令：</span><br><span class="line"></span><br><span class="line">git update-index --no--assume-unchanged Xml/config.xml  </span><br><span class="line">如果要忽略一个目录，打开 git bash，定位到目标目录下，后面的 Xml/test/ 是要忽略的目录的路径，执行命令：</span><br><span class="line"></span><br><span class="line">git update-index --assume-unchanged $(git ls-files Xml/test/ | tr <span class="string">'\n'</span> <span class="string">' '</span>)</span><br><span class="line">清除指定目录下没有被 push 过的文件和文件夹，执行命令：</span><br><span class="line"></span><br><span class="line">git clean -df supplier/web    https:<span class="comment">//learnku.com/articles/37298</span></span><br></pre></td></tr></table></figure>
<h3 id="crontab-截断"><a href="#crontab-截断" class="headerlink" title="crontab %截断"></a>crontab %截断</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">0</span> <span class="number">0</span> * * * cd /home/vg/odp/log &amp;&amp; mv *<span class="string">`date -d "-10 day" "+%Y%m%d"`</span>* archives</span><br><span class="line">crontab的执行情况，linux都会给对应的用户发邮件，因此可以通过邮件来定位问题。上面的任务在vg用户下，查看对应的邮件 /<span class="keyword">var</span>/spool/mail/vg</span><br><span class="line">Subject那一行：</span><br><span class="line">Subject: Cron cd /home/vg/odp/log &amp;&amp; mv *<span class="string">`date -d "-10 day" "+</span></span><br><span class="line"><span class="string">显示的命令不全，到加号就结束了，%和后面的部分丢失了，结合报错基本可以定位原因，%是crontab里的特殊符号，表示新的一行开始，所以前面的命令就被截断了。</span></span><br><span class="line"><span class="string">解决方式</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">如果crontab执行的命令中包含%需要用\转义，上面的例字改成这样就可以成功执行：</span></span><br><span class="line"><span class="string">0 0 * * * cd /home/vg/odp/log &amp;&amp; mv *`</span>date -d <span class="string">"-10 day"</span> <span class="string">"+\%Y\%m\%d"</span><span class="string">`* archives</span></span><br><span class="line"><span class="string">https://www.daemoncoder.com/a/%E8%AE%B0%E4%B8%80%E6%AC%A1crontab%E4%B8%ADdate%E5%91%BD%E4%BB%A4%E9%94%99%E7%94%A8%E5%AF%BC%E8%87%B4%E7%9A%84%E9%97%AE%E9%A2%98/4d54453d</span></span><br></pre></td></tr></table></figure>
<h3 id="查出访问量TOP10的IP"><a href="#查出访问量TOP10的IP" class="headerlink" title="查出访问量TOP10的IP"></a>查出访问量TOP10的IP</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">日志文件access.log格式如下：</span><br><span class="line"></span><br><span class="line"><span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span> - - [<span class="number">18</span>/Nov/<span class="number">2018</span>:<span class="number">17</span>:<span class="number">26</span>:<span class="number">54</span> +<span class="number">0800</span>] <span class="string">"GET / HTTP/1.0"</span> <span class="number">200</span> <span class="number">3283</span> <span class="string">"-"</span> <span class="string">""</span> <span class="string">"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36"</span> <span class="number">0.012</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span> <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">9000</span> daemoncoder.com <span class="string">"-"</span></span><br><span class="line">Linux命令：</span><br><span class="line"></span><br><span class="line">awk -F <span class="string">" "</span> <span class="string">'&#123;count[$1]++&#125; END &#123;for (i in count) &#123;printf("%s\t%d\n", i, count[i]);&#125;&#125;'</span> access.log | sort -nrk <span class="number">2</span> | head</span><br><span class="line">通过awk对日志中的每一行ip进行计数统计，并按ip count格式输出。</span><br><span class="line"></span><br><span class="line">通过sort命令按照第二列降序排序：-t 指定分割符是空格; -n指定按数字大小排序; -r 指定降序输出; -k 指定按分隔后的第二列排序</span><br><span class="line"></span><br><span class="line">通过head命令取出前十条。https:<span class="comment">//www.daemoncoder.com/a/%E4%B8%80%E8%A1%8CLinux%E5%91%BD%E4%BB%A4%E6%9F%A5%E5%87%BA%E8%AE%BF%E9%97%AE%E9%87%8FTOP10%E7%9A%84IP/4d773d3d</span></span><br></pre></td></tr></table></figure>
<h3 id="phpmyadmin-管理多台-MySQL"><a href="#phpmyadmin-管理多台-MySQL" class="headerlink" title="phpmyadmin 管理多台 MySQL"></a>phpmyadmin 管理多台 MySQL</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">复制 phpMyAdmin 根目录下的 config.sample.inc.php 文件，重命名为 config.inc.php；</span><br><span class="line">在文件中定义你的多台服务器配置信息：</span><br><span class="line">$hosts = [</span><br><span class="line">    <span class="number">1</span> =&gt; [<span class="string">'host'</span> =&gt; <span class="string">'localhost'</span>, <span class="string">'user'</span> =&gt; <span class="string">'root'</span>, <span class="string">'password'</span> =&gt; <span class="string">'root'</span>],</span><br><span class="line">    <span class="number">2</span> =&gt; [<span class="string">'host'</span> =&gt; <span class="string">'192.168.10.10'</span>, <span class="string">'user'</span> =&gt; <span class="string">'homestead'</span>, <span class="string">'password'</span> =&gt; <span class="string">'secret'</span>]</span><br><span class="line">];</span><br><span class="line">在加入以下代码片段，通过 <span class="keyword">for</span> 循环来读取多台 MySQL 服务器配置信息</span><br><span class="line"><span class="keyword">for</span>($i = <span class="number">1</span>; $i &lt;= count($hosts); $i++)&#123;</span><br><span class="line">    <span class="comment">/* Authentication type */</span></span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'auth_type'</span>] = <span class="string">'cookie'</span>;</span><br><span class="line">    <span class="comment">/* Server parameters */</span></span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'host'</span>] = $hosts[$i][<span class="string">'host'</span>];    <span class="comment">//修改host</span></span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'connect_type'</span>] = <span class="string">'tcp'</span>;</span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'compress'</span>] = <span class="literal">false</span>;</span><br><span class="line">    <span class="comment">/* Select mysqli if your server has it */</span></span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'extension'</span>] = <span class="string">'mysql'</span>;</span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'AllowNoPassword'</span>] = <span class="literal">true</span>;</span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'user'</span>] = $hosts[$i][<span class="string">'user'</span>];    <span class="comment">//修改用户名</span></span><br><span class="line">    $cfg[<span class="string">'Servers'</span>][$i][<span class="string">'password'</span>] = $hosts[$i][<span class="string">'password'</span>];    <span class="comment">//密码</span></span><br><span class="line">&#125;</span><br><span class="line">https:<span class="comment">//learnku.com/articles/31740</span></span><br></pre></td></tr></table></figure>
<h3 id="pull-request流程"><a href="#pull-request流程" class="headerlink" title="pull request流程"></a>pull request流程</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line">在 GitHub 上把本项目 fork 到自己的仓库，如 &lt;your-username&gt;<span class="regexp">/php-developer-prepares，然后 clone 到本地，并设置用户信息。</span></span><br><span class="line"><span class="regexp">$ git clone git@github.com:&lt;your-username&gt;/</span>php-developer-prepares.git</span><br><span class="line">$ cd php-developer-prepares</span><br><span class="line">$ git config user.name <span class="string">"yourname"</span></span><br><span class="line">$ git config user.email <span class="string">"your email"</span></span><br><span class="line">修改代码后提交，并推送到自己的仓库。</span><br><span class="line">$ #do some change on the content</span><br><span class="line">$ git commit -am <span class="string">"Fix issue #1: change helo to hello"</span></span><br><span class="line">$ git push</span><br><span class="line">在 GitHub 网站上提交 pull request。</span><br><span class="line">定期使用项目仓库内容更新自己仓库内容。</span><br><span class="line">$ git remote add upstream https:<span class="comment">//github.com/zacao/php-developer-prepares</span></span><br><span class="line">$ git fetch upstream</span><br><span class="line">$ git checkout master</span><br><span class="line">$ git rebase upstream/master</span><br><span class="line">$ git push -f origin master</span><br></pre></td></tr></table></figure>
<h3 id="SSH-也通过-SS-代理"><a href="#SSH-也通过-SS-代理" class="headerlink" title="SSH 也通过 SS 代理"></a>SSH 也通过 SS 代理</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"> 配置您的 ~<span class="regexp">/.ssh/</span>config 文件，增加以下的内容即可：</span><br><span class="line"></span><br><span class="line">Host github.com</span><br><span class="line">   HostName github.com</span><br><span class="line">   User git</span><br><span class="line">   ProxyCommand nc -v -x <span class="number">127.0</span><span class="number">.0</span><span class="number">.1</span>:<span class="number">1086</span> %h %p</span><br><span class="line">https:<span class="comment">//learnku.com/articles/37108</span></span><br></pre></td></tr></table></figure>
<h3 id="Github-关键字进行搜索"><a href="#Github-关键字进行搜索" class="headerlink" title="Github 关键字进行搜索"></a>Github 关键字进行搜索</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">in</span>:name Laravel</span><br><span class="line"><span class="keyword">in</span>:readme Laravel</span><br><span class="line"><span class="keyword">in</span>:decription Laravel</span><br><span class="line"><span class="keyword">in</span>:description Laravel stars:&gt;<span class="number">1000</span> forks:&gt;<span class="number">1000</span></span><br><span class="line"><span class="keyword">in</span>:descrption Laravel stars:<span class="number">1000.</span><span class="number">.2000</span></span><br><span class="line"><span class="keyword">in</span>:description 验证码 language:php</span><br><span class="line">in:description 验证码 language:php pushed:&gt;2019-05-01 # 过滤大于 2019-05-01之后提交的</span><br><span class="line">in:description 验证码 language:php created:&gt;2019-05-01 # 过滤大于 2019-05-01创建的</span><br><span class="line">user:overtrue</span><br><span class="line">user:laravel</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38106 https://github.com/search/advanced</span></span><br><span class="line">followers:&gt;<span class="number">1000</span> language:PHP location:China</span><br></pre></td></tr></table></figure>
<h3 id="Bash-单命令行解释"><a href="#Bash-单命令行解释" class="headerlink" title="Bash 单命令行解释"></a>Bash 单命令行解释</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">清空文件  &gt; file</span><br><span class="line"> echo <span class="string">"some string"</span> &gt; file</span><br><span class="line"> echo <span class="string">"foo bar baz"</span> &gt;&gt; file</span><br><span class="line"> line=$(head <span class="number">-1</span> file)</span><br><span class="line"> line=<span class="string">`head -1 file`</span> </span><br><span class="line"> 一行行地读取文件 </span><br><span class="line"> </span><br><span class="line"> $ <span class="keyword">while</span> read -r line; <span class="keyword">do</span></span><br><span class="line">     # do something with $line</span><br><span class="line"> done &lt; file</span><br><span class="line"> </span><br><span class="line"> $ str=<span class="string">"hello world"</span></span><br><span class="line"> $ echo $&#123;<span class="attr">str</span>:<span class="number">6</span>&#125;<span class="comment">//world</span></span><br><span class="line"> echo $&#123;<span class="attr">str</span>:<span class="number">7</span>:<span class="number">2</span>&#125;</span><br><span class="line"> echo $&#123;#str&#125;//12</span><br><span class="line"> $ <span class="keyword">if</span> [[ $str =~ [<span class="number">0</span><span class="number">-9</span>]+.[<span class="number">0</span><span class="number">-9</span>]+ ]]; then</span><br><span class="line">     # 执行一些操作</span><br><span class="line"> fi</span><br><span class="line"> $ <span class="keyword">if</span> [[ $file = *.zip ]]; then</span><br><span class="line">     # 执行一些操作</span><br><span class="line"> fi</span><br><span class="line"> $ <span class="keyword">if</span> [[ $answer = [Yy]* ]]; then</span><br><span class="line">     # 执行一些操作</span><br><span class="line"> fi</span><br><span class="line"> $ str=baz-foo-bar-foo-foo</span><br><span class="line"> $ echo $&#123;str/foo/bar&#125;</span><br><span class="line"> baz-bar-bar-foo-foo</span><br><span class="line"> $ echo <span class="string">"$x$y"</span><span class="comment">//合并</span></span><br><span class="line"> $ echo foo&#123;,,,,,,,,,,&#125;<span class="comment">//重复生成</span></span><br><span class="line"> echo &#123;a,b,c&#125;&#123;<span class="number">1</span>,<span class="number">2</span>,<span class="number">3</span>&#125;</span><br><span class="line"> a1 a2 a3 b1 b2 b3 c1 c2 c3</span><br><span class="line">printf <span class="string">"%02d "</span> &#123;<span class="number">0.</span><span class="number">.9</span>&#125;<span class="comment">//00 01 02 03 04 05 06 07 08 09</span></span><br><span class="line">echo &#123;<span class="number">1.</span><span class="number">.100</span>&#125;</span><br><span class="line">$ echo &#123;a..z&#125;<span class="comment">//a b c d e f g h i j k l m n o p q r s t u v w x y z</span></span><br><span class="line">echo $(printf <span class="string">"%c"</span> &#123;a..z&#125;)</span><br><span class="line">abcdefghijklmnopqrstuvwxyz</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/38528</span></span><br><span class="line"> https:<span class="comment">//learnku.com/articles/38449</span></span><br></pre></td></tr></table></figure>
<h3 id="列出目录下所有被-git-忽略的文件"><a href="#列出目录下所有被-git-忽略的文件" class="headerlink" title="列出目录下所有被 git 忽略的文件"></a>列出目录下所有被 git 忽略的文件</h3><p>find . -type f  | git check-ignore –stdin</p>
<h3 id="SSH-闲置时间过长而断开"><a href="#SSH-闲置时间过长而断开" class="headerlink" title="SSH 闲置时间过长而断开"></a>SSH 闲置时间过长而断开</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  修改/etc/ssh/sshd_config配置文件，找到ClientAliveCountMax（单位为分钟）修改你想要的值，</span></span><br><span class="line"><span class="comment">//   执行</span></span><br><span class="line">$ service sshd reload </span><br><span class="line"></span><br><span class="line"><span class="comment">//  找到所在用户的.ssh目录,如root用户该目录在：</span></span><br><span class="line">$  /root/.ssh/</span><br><span class="line"><span class="comment">//  在该目录创建config文件</span></span><br><span class="line">$ vi /root/.ssh/config</span><br><span class="line"><span class="comment">//  加入下面一句：</span></span><br><span class="line">ServerAliveInterval <span class="number">60</span></span><br><span class="line"><span class="comment">//  保存退出，重新开启root用户的shell，则再ssh远程服务器的时候，</span></span><br><span class="line">不会因为长时间操作断开。应该是加入这句之后，ssh客户端会每隔一</span><br><span class="line">段时间自动与ssh服务器通信一次，所以长时间操作不会断开。</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38759</span></span><br><span class="line"><span class="comment">// 修改/etc/profile配置文件</span></span><br><span class="line">$ vi /etc/profile</span><br><span class="line">增加：TMOUT=<span class="number">1800</span></span><br><span class="line">这样<span class="number">30</span>分钟没操作就自动LOGOUT</span><br></pre></td></tr></table></figure>
<h3 id="安装-swoole-laravelS"><a href="#安装-swoole-laravelS" class="headerlink" title="安装 swoole laravelS"></a>安装 swoole laravelS</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">pecl install swoole </span><br><span class="line">$ pecl channel-update pecl.php.net</span><br><span class="line">$ php -r <span class="string">"print_r(openssl_get_cert_locations());"</span></span><br><span class="line">[default_cert_file] =&gt; <span class="regexp">/usr/</span>lib/ssl/cert.pem</span><br><span class="line">[default_cert_file_env] =&gt; SSL_CERT_FILE</span><br><span class="line">[default_cert_dir] =&gt; <span class="regexp">/usr/</span>lib/ssl/certs</span><br><span class="line">[default_cert_dir_env] =&gt; SSL_CERT_DIR</span><br><span class="line">[default_private_dir] =&gt; <span class="regexp">/usr/</span>lib/ssl/private</span><br><span class="line">[default_default_cert_area] =&gt; <span class="regexp">/usr/</span>lib/ssl</span><br><span class="line">[ini_cafile] =&gt;</span><br><span class="line">[ini_capath] =&gt;</span><br><span class="line">安装证书</span><br><span class="line">$ wget -c https:<span class="comment">//curl.haxx.se/ca/cacert.pem  /usr/local/openssl/cert.pem --no-check-certificate</span></span><br><span class="line">开启 swoole 扩展</span><br><span class="line">$ echo <span class="string">'extension=swoole.so'</span> &gt;&gt; <span class="regexp">/etc/</span>php/<span class="number">7.3</span>/mods-available/swoole.ini</span><br><span class="line">$  ln -s /etc/php/<span class="number">7.3</span>/mods-available/swoole.ini /etc/php/<span class="number">7.3</span>/cli/conf.d/<span class="number">20</span>-swoole.ini</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/38355</span></span><br></pre></td></tr></table></figure>
<h3 id="error-src-refspec-matches-more-than-one"><a href="#error-src-refspec-matches-more-than-one" class="headerlink" title="error src refspec matches more than one"></a>error src refspec matches more than one</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git push origin test</span><br><span class="line">error: src refspec test matches more than one.</span><br><span class="line">error: failed to push some refs to</span><br><span class="line">git tag |grep test</span><br><span class="line">因为有一个与当前提交分支同名的标签</span><br><span class="line">git tag -d test</span><br><span class="line">git push origin test</span><br></pre></td></tr></table></figure>
<h3 id="ssh-连接-实现免密码登陆"><a href="#ssh-连接-实现免密码登陆" class="headerlink" title="ssh 连接 实现免密码登陆"></a>ssh 连接 实现免密码登陆</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span>主配置文件于/etc/ssh/sshd_config</span><br><span class="line"><span class="number">2.</span>Port <span class="number">22</span> 端口声明指定sshd服务器将侦听连接的端口 </span><br><span class="line">如需更改端口 直接添加后  测试完成 再删除 <span class="number">22</span></span><br><span class="line"><span class="number">3.</span>PermitRootLogin 选择是否允许root登录</span><br><span class="line"><span class="number">4.</span>LoginGraceTime 指定在未成功登录的情况下保持连接活动的秒数</span><br><span class="line">[root@7S ssh]# sudo service ssh restart  重启服务</span><br><span class="line">[root@7S ssh]# sudo systemctl restart ssh</span><br><span class="line"></span><br><span class="line">[root@7S ssh]# systemctl stop firewalld.service //关闭防火墙</span><br><span class="line">    [root@7S ssh]# systemctl is-enabled firewalld.service //查看防火墙状态</span><br><span class="line">    enabled</span><br><span class="line">    [root@7S ssh]# firewall-cmd --zone=public --add-port=1212/tcp --permanent 添加 放行端口 1212</span><br><span class="line">    FirewallD is not running <span class="comment">// 防火墙关闭</span></span><br><span class="line">    [root@7S ssh]# systemctl restart firewalld.service //启动</span><br><span class="line">    [root@7S ssh]# firewall-cmd --zone=public --add-port=1212/tcp --permanent //继续添加</span><br><span class="line">    success </span><br><span class="line">     [root@7S ssh]# firewall-cmd --zone=public --list-ports //查看所有端口</span><br><span class="line">[root@7S ssh]# ssh-keygen -t rsa //创建</span><br><span class="line">按 Enter 键接受默认值  (Mac)密钥在〜/.ssh/id_rsa.pub和〜/.ssh / id_rsa中 (<span class="built_in">window</span> 系统不一样 Admin文件名不一样) /C/users/Admin/.ssh/id_rsa</span><br><span class="line">ssh-copy-id root@<span class="number">192.168</span><span class="number">.100</span><span class="number">.00</span> <span class="comment">// 将公钥复制到远程服务器 输入密码 下次不需要使用密码 即可登录</span></span><br><span class="line"></span><br><span class="line">更改 端口 登录</span><br><span class="line">$ ssh -p <span class="number">1212</span> root@<span class="number">192.168</span><span class="number">.100</span><span class="number">.00</span></span><br><span class="line"></span><br><span class="line">安全考虑 禁用密码验证</span><br><span class="line"></span><br><span class="line">[root@7S ssh]# /etc/ssh/sshd_config</span><br><span class="line"><span class="comment">// PasswordAuthentication no //去掉注释 改为 no</span></span><br><span class="line"><span class="comment">// PubkeyAuthentication yes   // 默认不修改</span></span><br><span class="line"><span class="comment">// ChallengeResponseAuthentication no // 默认不修改</span></span><br><span class="line">sudo systemctl restart ssh <span class="comment">// 重启服务 如有错误 关闭 SELinux 或者 向 SELinux 中添加修改的 SSH 端口 (如下)</span></span><br><span class="line"></span><br><span class="line">ssh-copy-id -i ~<span class="regexp">/.ssh/i</span>d_rsa.pub root@<span class="number">192.168</span><span class="number">.100</span><span class="number">.000</span> <span class="comment">// 将本机的 id_rsa.pub 公钥文件内容复制到远程目标机的.ssh/authorized_keys 文件中</span></span><br><span class="line"></span><br><span class="line">本地复制: scp .ssh/id_rsa.pub user@<span class="number">192.168</span><span class="number">.1</span><span class="number">.100</span>:<span class="regexp">/home/</span>root/</span><br><span class="line"></span><br><span class="line">服务器操作:</span><br><span class="line"></span><br><span class="line">[root@7S ssh]# mkdir -p /home/root/.ssh/</span><br><span class="line">[root@7S ssh]# mv /home/root/id_rsa.pub /home/root/.ssh/authorized_keys  //authorized_keys 必须如此命名</span><br><span class="line">https:<span class="comment">//learnku.com/articles/38761</span></span><br></pre></td></tr></table></figure>
<h3 id="CentOS-部署-Laravel-应用"><a href="#CentOS-部署-Laravel-应用" class="headerlink" title="CentOS 部署 Laravel 应用"></a>CentOS 部署 Laravel 应用</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">$ yum install nginx </span><br><span class="line">$ systemctl nginx start   # 启动 Nginx </span><br><span class="line">$ systemctl nginx stop    # 停止 Nginx </span><br><span class="line">$ systemctl nginx restart # 重启 Nginx</span><br><span class="line">$ systemctl enable nginx.service # 设置开机自启动</span><br><span class="line">$ systemctl disable nginx # 禁用 Nginx 开机启动</span><br><span class="line">$ systemctl list-dependencies | grep nginx # 检查开机自启动是否设置成功</span><br><span class="line">浏览器访问不成功 解决办法</span><br><span class="line">方法一: systemctl stop firewalld.service  # 关闭防火墙</span><br><span class="line">方法二: firewall-cmd --zone=public --add-port=80/tcp --permanent # 添加80端口</span><br><span class="line">firewall-cmd --reload # 重启防火墙</span><br><span class="line">firewall-cmd --list-ports # 查看是否添加成功</span><br><span class="line">1212/tcp 80/tcp # 显示 即成功 1212 设置的其他端口</span><br><span class="line">浏览器访问</span><br><span class="line">Welcome to nginx! # 成功显示</span><br><span class="line">安装 PHP</span><br><span class="line"></span><br><span class="line">$ yum install -y php72w php72w-cli php72w-fpm # PHP 自身 / cli PHP 的命令行接口 / 用于管理 PHP 进程，并提供 FastCGI 接口与 Nginx 交互</span><br><span class="line">$ yum install -y php72w-mbstring php72w-xml php72w-bcmath # 安装扩展 </span><br><span class="line">$ php -m # 查看扩展</span><br><span class="line">$ php -v # 查看 PHP 版本</span><br><span class="line">$ systemctl restart php-fpm # 重启 PHP-FPM </span><br><span class="line">$ systemctl start php-fpm # 启动 PHP-FPM </span><br><span class="line">$ systemctl stop php-fpm # 停止 PHP-FPM</span><br><span class="line">$ systemctl enable php-fpm # 启用 PHP-FPM 开机启动 </span><br><span class="line">$ systemctl disable php-fpm # 禁用 PHP-FPM 开机启动  </span><br><span class="line">$ ps aux | grep php # 确认 PHP-FPM 正常运行 </span><br><span class="line"></span><br><span class="line">$ yum install -y git</span><br><span class="line">$ git --version # 查看 git 版本</span><br><span class="line"># 生成 SSH 秘钥</span><br><span class="line">$ ls -al ~<span class="regexp">/.ssh # 查看是否 存在 `id_rsa` 与文件 `id_rsa.pub`</span></span><br><span class="line"><span class="regexp">$ ssh-keygen -t rsa -C "your_email@example.com" # 一路回车【密码为空】</span></span><br><span class="line">$ ls -al ~/.ssh # 再次查看是否生成成功</span><br><span class="line">$ cat ~/.ssh/id_rsa.pub # 查看公钥内容</span><br><span class="line">Composer</span><br><span class="line">############################################</span><br><span class="line">$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"  # 或者使用 `$ wget -O composer-setup.php https://getcomposer.org/installer` $ php -r "if (hash_file('sha384', 'composer-setup.php') === 'a5c698ffe4b8e849a443b120cd5ba38043260d5c4023dbf93e1558871f1f07f58274fc6f4c93bcfd858c6bd0775cd8d1') &#123; echo 'Installer verified'; &#125; else &#123; echo 'Installer corrupt'; unlink('composer-setup.php'); &#125; echo PHP_EOL;" </span><br><span class="line">$ php composer-setup.php --filename=composer --install-dir=<span class="regexp">/usr/</span>local/bin --version=<span class="number">1.9</span><span class="number">.0</span> </span><br><span class="line">$ php -r "unlink('composer-setup.php');"  # 检查安装情况 </span><br><span class="line">$ composer --version # 淘宝全量镜像【https://learnku.com/composer/wikis/30594】 </span><br><span class="line">$ composer config -g repo.packagist composer https:<span class="comment">//mirrors.aliyun.com/composer/  </span></span><br><span class="line"></span><br><span class="line">$ rpm -ivh https:<span class="comment">//dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm # 安装 mysql 官方 yum 源</span></span><br><span class="line">$ yum list |  grep mysql # 查看 MySQL yum 源 发现只有 mysql80 的包，这是因为没有开启 mysql57 的包 </span><br><span class="line">$ yum-config-manager --disable mysql80-community # 关闭 80 包，开启 57 包</span><br><span class="line">$ yum-config-manager --enable mysql57-community # 遇到问题 yum-config-manager: command not found  解决 安装 yum -y install yum-utils</span><br><span class="line">$ yum list |  grep mysql # 发现有了 mysql57 的包</span><br><span class="line">$ yum install -y mysql-community-server # 安装 mysql</span><br><span class="line">$ yum install -y mysql-community-client # 根据需要安装（可不装）</span><br><span class="line">$ systemctl start mysqld # 启动 mysql</span><br><span class="line">$ systemctl stop mysqld # 停止 mysql</span><br><span class="line">$ service mysqld status # 或 ps -ef | grep mysql //检查mysql正常启动</span><br><span class="line">$ systemctl enable mysqld.service #设置mysqld服务开机自启动 　</span><br><span class="line">$ systemctl list-dependencies | grep mysqld #检查mysqld开机自启动是否设置成功</span><br><span class="line">$ grep 'temporary password' /var/log/mysqld.log # 查看超级账户 root 临时密码 mysql5.7 增强了安全机制, 系统会自动生成一个随机的密码</span><br><span class="line">$ mysql  -uroot  -p</span><br><span class="line">mysql&gt; ALTER USER "root"@"localhost" IDENTIFIED BY '你的新密码'; # 修改超级账户 root 密码</span><br><span class="line">mysql&gt; flush privileges;</span><br><span class="line">mysql&gt; exit;</span><br><span class="line">$ systemctl restart mysqld.service</span><br><span class="line">https:<span class="comment">//learnku.com/articles/35573#reply123613</span></span><br></pre></td></tr></table></figure>
<h3 id="Docker-Contos-搭建-PHP-环境"><a href="#Docker-Contos-搭建-PHP-环境" class="headerlink" title="Docker Contos 搭建 PHP 环境"></a>Docker Contos 搭建 PHP 环境</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">docker pull nginx <span class="comment">// 拉取官方镜像</span></span><br><span class="line">docker images <span class="comment">// 查看</span></span><br><span class="line">docker run -p <span class="number">80</span>:<span class="number">80</span> -d --name mynginx -v /docker/www:<span class="regexp">/usr/</span>share/nginx/www nginx <span class="comment">// 开启 nginx 应用容器</span></span><br><span class="line">-p <span class="number">80</span>:<span class="number">80</span>：将容器的<span class="number">80</span>端口映射到主机的<span class="number">80</span>端口 -d 后台运行(守护进程) --name mynginx：将容器命名为mynginx -v 将主机中当前目录下的www挂载到容器的www目录</span><br><span class="line"></span><br><span class="line">docker ps -a <span class="comment">// 查看容器启动情况</span></span><br><span class="line">docker pull php:<span class="number">7.2</span>-fpm <span class="comment">// 拉取官方 PHP 镜像</span></span><br><span class="line">docker images <span class="comment">// 查看</span></span><br><span class="line">docker run -p <span class="number">9000</span>:<span class="number">9000</span> -d --name myphp-fpm -v /docker/www:<span class="regexp">/usr/</span>share/nginx/www php:<span class="number">7.1</span>-fpm <span class="comment">// 开启 php-frm 应用容器</span></span><br><span class="line">docker ps -a <span class="comment">// 查看容器启动情况</span></span><br><span class="line">docker inspect myphp-fpm | grep <span class="string">"IPAddress"</span> <span class="comment">// 查看 ip 信息</span></span><br><span class="line"><span class="string">"SecondaryIPAddresses"</span>: <span class="literal">null</span>,</span><br><span class="line"><span class="string">"IPAddress"</span>: <span class="string">"172.17.0.3"</span>,</span><br><span class="line"><span class="string">"IPAddress"</span>: <span class="string">"172.17.0.3"</span>,</span><br><span class="line">[root@localhost ~]# docker exec -it mynginx bash // 进入容器</span><br><span class="line">vi /etc/nginx/conf.d/<span class="keyword">default</span>.conf <span class="comment">// 修改配置文件</span></span><br><span class="line">然后使用 ctrl + p + q 退出容器，使用 exit 的话会让容器停止。</span><br><span class="line">docker cp mynginx:<span class="regexp">/etc/</span>nginx/conf.d/<span class="keyword">default</span>.conf ./<span class="keyword">default</span>.conf</span><br><span class="line"></span><br><span class="line">https:<span class="comment">//learnku.com/articles/38766</span></span><br></pre></td></tr></table></figure>
<h3 id="git-笔记"><a href="#git-笔记" class="headerlink" title="git 笔记"></a>git 笔记</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">git clone 命令默认的只会建立master分支 <span class="comment">// 特别提醒</span></span><br><span class="line">git clone -b [new_branch_name]  仓库地址 <span class="comment">// clone时创建新的分支替代默认origin/master</span></span><br><span class="line">git clone 仓库地址  <span class="comment">// 从远程库拉到本地 文件名为仓库名 如 git@gitee.com:momingsixiali/git.git 拉到本地文件名为 git</span></span><br><span class="line">git clone 仓库地址 <span class="string">"指定目录"</span> <span class="comment">// 拉到本地文件名 为 指定的目录 如 git clone git@gitee.com:momingsixiali/git.git zhiding 本地文件名为 zhiding</span></span><br><span class="line"></span><br><span class="line">git mv demo demo1 <span class="comment">// 不会破坏git历史 等效于 如下:</span></span><br><span class="line">mv demo demo1 <span class="comment">// 修改文件名</span></span><br><span class="line">git add demo1 <span class="comment">// 添加到暂存区</span></span><br><span class="line">git rm demo <span class="comment">// 更改demo的提交历史到 demo1</span></span><br><span class="line"></span><br><span class="line">git reset --hard <span class="comment">// 危险命令 分支的指针都指向上一个提交  无法找回 移动 HEAD-&gt;更新索引-&gt;更新暂存区工作区</span></span><br><span class="line">git reset --soft  <span class="comment">//  分支的指针都指向上一个提交 本次提交还在 只是不显示</span></span><br><span class="line">git reset --mixed  <span class="comment">//  分支的指针都指向上一个提交 只是回退暂存区 工作区还在 推荐使用 也是 git 默认</span></span><br><span class="line"></span><br><span class="line">git grep login <span class="comment">// 查找该仓库里所有使用'login'的地方 相当于 Linux中的 grep 返回如下</span></span><br><span class="line">    app/Http/Controllers/Auth/LoginController.php:     * Where to redirect users after login.</span><br><span class="line">git grep -n login <span class="comment">// 显示 行号 </span></span><br><span class="line">git grep --name-only login <span class="comment">// 只显示文件名</span></span><br><span class="line">   app/Http/Controllers/Auth/LoginController.php</span><br><span class="line">   git grep -c login <span class="comment">// 查看每个文件里有多少行匹配</span></span><br><span class="line">      app/Http/Controllers/Auth/LoginController.php:<span class="number">1</span></span><br><span class="line"> git grep login <span class="number">5027</span>c63 <span class="comment">// 指定提交索引 找</span></span><br><span class="line"> git grep -e <span class="string">'name'</span> --and -e email <span class="comment">// 同时满足 name 和 email </span></span><br><span class="line">    app/Models/User.php:        <span class="string">'name'</span>, <span class="string">'email'</span>, <span class="string">'password'</span>,</span><br><span class="line">    composer.lock:            <span class="string">"name"</span>: <span class="string">"egulias/email-validator"</span>,</span><br><span class="line"> git grep --all-match -e <span class="string">'name'</span> -e email <span class="number">97</span>bacf05d4 <span class="comment">// 满足name 或 email </span></span><br><span class="line"> git grep -e <span class="string">'name'</span> --and  -e  -e MAX .</span><br><span class="line"> git grep -e <span class="string">'password'</span> --and ( -e name -e email ) <span class="comment">//  同时满足 password 和 (name 或者 email)</span></span><br><span class="line"> <span class="comment">// 可组合使用</span></span><br><span class="line"> git grep  -n -e <span class="string">'password'</span> --and -e email <span class="number">97</span>bacf05d4</span><br><span class="line"> </span><br><span class="line"> git log -p <span class="comment">// 显示每个commit具体修改的内容，输出的形式以diff的形式给出</span></span><br><span class="line"> git show <span class="comment">// 同git log -p输出类似，不同在于show只显示一个commit的内容，如果不指定commit hash, 它默认输出HEAD指向commit的内容</span></span><br><span class="line"> git shortlog <span class="comment">// 显示汇总信息，以用户进行分类 返回如下</span></span><br><span class="line">     moming (<span class="number">6</span>):</span><br><span class="line">           Merge branch <span class="string">'dev'</span> <span class="keyword">of</span> https:<span class="comment">//github.com/wujianan/shop into dev</span></span><br><span class="line">           添加忽略文件</span><br><span class="line">           注册登录</span><br><span class="line">           邮箱验证功能</span><br><span class="line">     momingsixiali (<span class="number">1</span>):</span><br><span class="line">           项目初始化</span><br><span class="line">   git shortlog -s <span class="comment">// 显示用户 提交次数 按提交时间排序</span></span><br><span class="line">   git shortlog -n <span class="comment">// 显示用户 提交次数 进行倒序排列</span></span><br><span class="line"> git log  --author=moming <span class="comment">// 显示 moming 的提交, 限定输出给定的用户</span></span><br><span class="line"> git log <span class="number">-2</span> <span class="comment">// 限制 显示输出的数量 本次输出 2个</span></span><br><span class="line"> git log --after <span class="string">'12-22-2019'</span>  <span class="comment">//  --after和--before 限定指定日期的log</span></span><br><span class="line"> git log --decorate --oneline <span class="comment">// 显示对应commit所属的branch和tag信息</span></span><br><span class="line"> git log --all <span class="comment">// 所有分支</span></span><br><span class="line"> git log --graph <span class="comment">// 演化历史 包括所有分支</span></span><br><span class="line"> git log --oneline  <span class="comment">// 简化输出  </span></span><br><span class="line">   git show <span class="number">72939</span>  <span class="comment">// 显示指定提交的相关信息</span></span><br><span class="line">   git show <span class="number">72939</span>^&#123;tree&#125; <span class="comment">//显示指定提交的目录结构</span></span><br><span class="line">   git show v1  <span class="comment">// 显示指定 tag </span></span><br><span class="line">git diff <span class="comment">// 显示工作区 和暂存区的 不同</span></span><br><span class="line">git diff --stat <span class="comment">// 显示简单的 比较信息</span></span><br><span class="line">git diff master <span class="comment">// 查看当前分支 与 master 分支的 不同之处</span></span><br><span class="line">git diff SHA1 SHA2 <span class="comment">// 比较两个历史版本之间的差异   </span></span><br><span class="line">   git push &lt;远程主机名&gt; &lt;本地分支名&gt;:&lt;远程分支名&gt; // 将本地分支的更新，推送到远程</span><br><span class="line">   git push origin :master // 危险 删除远程仓库的分支 等效于 git push origin --delete master</span><br><span class="line">   git push //当前分支只有一个追踪分支 可省略 &lt;远程主机名&gt; &lt;本地分支名&gt;:&lt;远程分支名&gt;</span><br><span class="line">   git push -u origin master // 将本地的master分支推送到origin远程，同时指定origin为默认，后面就可以不加任何参数使用git push</span><br><span class="line">   git fetch 和 git pull  // 功能是大致相同,都是起到了更新代码的作用 git pull看起来更像git fetch + get merge 建议使用 git fetch + get merge   git pull 一旦代码有问题，很难找到出错的地方https://learnku.com/articles/38780</span><br></pre></td></tr></table></figure>
<h3 id="Shell-变量高级用法"><a href="#Shell-变量高级用法" class="headerlink" title="Shell-变量高级用法"></a>Shell-变量高级用法</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">echo $&#123;PATH/bin/BIN&#125;    <span class="comment">// 单个替换</span></span><br><span class="line">echo $&#123;PATH<span class="comment">//bin/BIN&#125;   // 全部替换</span></span><br><span class="line">echo $&#123;#var_str&#125;</span><br><span class="line">[wonbin@localhost ~]$ string=<span class="string">"everything is just beginning"</span></span><br><span class="line">[wonbin@localhost ~]$ echo <span class="string">`expr index "$string" ux`</span></span><br><span class="line"><span class="number">16</span></span><br><span class="line">echo $&#123;<span class="attr">var_str</span>:<span class="number">3</span>:<span class="number">5</span>&#125;  <span class="comment">// 方法二， 开始位置3， 长度5</span></span><br><span class="line">echo <span class="string">`expr substr "$var_str" 1 5`</span>   <span class="comment">// 方法五， 索引从开始1计数</span></span><br><span class="line">https:<span class="comment">//learnku.com/articles/39190</span></span><br></pre></td></tr></table></figure>
<h3 id="删除文件占用空间"><a href="#删除文件占用空间" class="headerlink" title="删除文件占用空间"></a>删除文件占用空间</h3><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">在清理过服务器上一个高达 <span class="number">100</span> 多 G 的文件后，使用 df -h 查看存储空间仍然 <span class="number">100</span>%。使用 du -h -x --max-depth=<span class="number">1</span> 进行查看与 df -h 的结果不一致</span><br><span class="line">使用 lsof |grep deleted 进行查看是否有删除操作的异常进程</span><br><span class="line"></span><br><span class="line">发现有一个 php 进程在占用， kill 掉相关进程后恢复正常https:<span class="comment">//learnku.com/articles/39534</span></span><br></pre></td></tr></table></figure>
<p><a href="https://learnku.com/articles/39274" target="_blank" rel="noopener">Linux 性能优化笔记</a></p>
<p><a href="https://learnku.com/articles/37335" target="_blank" rel="noopener">Nginx+rtmp 模块搭建流媒体视频点播服务</a></p>
<p><a href="https://github.com/yeasy/docker_practice" target="_blank" rel="noopener">Docker — 从入门到实践</a></p>
<p><a href="https://learnku.com/linux/wikis/36492" target="_blank" rel="noopener">linux wiki</a></p>
<p><a href="https://learnku.com/articles/37287" target="_blank" rel="noopener">Nginx 站点开启 HTTPS </a></p>
<p><a href="https://learnku.com/articles/37157#reply119179" target="_blank" rel="noopener">Docker 中安装 RabbitMQ</a></p>
<p><a href="https://learnku.com/articles/36986" target="_blank" rel="noopener">Nginx 内嵌变量</a></p>
<p><a href="https://learnku.com/articles/33689" target="_blank" rel="noopener">Git 实现 Laravel 项目的自动化部署</a></p>
<p><a href="https://learnku.com/articles/36857" target="_blank" rel="noopener">Nginx 代理缓存</a></p>
<p><a href="https://learnku.com/articles/36852#reply118312" target="_blank" rel="noopener">Git 的代码自动发布</a></p>
<p><a href="https://learnku.com/articles/36207" target="_blank" rel="noopener">Elasticsearch  es安装和简单配置</a></p>
<p><a href="https://learnku.com/linux/t/36120" target="_blank" rel="noopener">配置安全的 SSH 服务</a></p>
<p><a href="https://learnku.com/linux/t/36233" target="_blank" rel="noopener">使用 fail2ban 来防范 SSH 暴力破解</a></p>
<p><a href="https://crontab.guru/" target="_blank" rel="noopener">在线crontab</a></p>
<p><a href="https://github.com/jianyan74/dockerfiles" target="_blank" rel="noopener">docker 快速搭建稳定安全的开发/生产环境</a></p>
<p><a href="https://gleehub.com/program/wsl-xia-you-ya-di-coding.html" target="_blank" rel="noopener">windows 10 WSL编码</a></p>
<p><a href="https://learnku.com/articles/33469" target="_blank" rel="noopener">初识 Shell</a></p>
<p><a href="http://einverne.github.io/post/2019/01/html-to-pdf.html" target="_blank" rel="noopener">html 转 pdf 命令行工具 wkhtmltopdf </a></p>
<p><a href="https://me.jinchuang.org/archives/301.html" target="_blank" rel="noopener">Centos7 搭建 Nextcloud个人网盘</a></p>
<p><a href="https://github.com/mylxsw/growing-up/blob/master/doc/%E4%B8%89%E5%8D%81%E5%88%86%E9%92%9F%E5%AD%A6%E4%BC%9ASED.md" target="_blank" rel="noopener">三十分钟学会sed</a></p>
<p><a href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/index.html" target="_blank" rel="noopener">Linux工具快速教程</a></p>
<p><a href="http://qinghua.github.io/sed/" target="_blank" rel="noopener">看例子学sed</a></p>
<p><a href="https://michael728.github.io/2018/07/05/linux-useful-commands-in-work/" target="_blank" rel="noopener">工作中常用的 Linux 命令</a></p>
<p><a href="https://michael728.github.io/2019/04/14/linux-useful-shell-commands-in-work/" target="_blank" rel="noopener">工作中常用的 Shell 命令及技巧</a></p>
<p><a href="https://linux.hellocode.name/user-group.html" target="_blank" rel="noopener">PHPer 必知必会的 Linux 命令</a></p>
<p><a href="https://linuxtools-rst.readthedocs.io/zh_CN/latest/index.html#" target="_blank" rel="noopener">Linux工具快速教程</a></p>
<p><a href="https://segmentfault.com/a/1190000016648034" target="_blank" rel="noopener">你可能不知道的shell技巧</a></p>
<p><a href="https://neuqzxy.github.io/2017/07/08/wget%E7%9A%8415%E4%B8%AA%E9%9C%87%E6%92%BC%E7%9A%84%E4%BE%8B%E5%AD%90/" target="_blank" rel="noopener">wget的15个震撼的例子</a></p>
<p><a href="https://www.restran.net/2015/10/19/linux-practice-notes/" target="_blank" rel="noopener">Linux 踩坑记</a></p>
<p><a href="https://github.com/Nick233333/phper-linux-gitbook" target="_blank" rel="noopener">PHPer 必知必会的 Linux 命令</a></p>
<p><a href="https://github.com/jlevy/the-art-of-command-line" target="_blank" rel="noopener">命令行的艺术</a></p>
<p><a href="https://www.njphper.com/posts/680ebdf2.html" target="_blank" rel="noopener">Nginx 学习笔记时序图</a></p>
<p><a href="https://learnku.com/articles/28500" target="_blank" rel="noopener">Windows 10 安装体验</a></p>
<p><a href="https://coolshell.cn/articles/19219.html" target="_blank" rel="noopener">打造高效的工作环境 – SHELL 篇https://github.com/coolshellx/articles</a></p>
<p><a href="https://michael728.github.io/2018/07/05/linux-useful-commands-in-work/" target="_blank" rel="noopener">工作中常用的 Linux 命令</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/linux/" rel="tag"># linux</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/03/27/laravel-笔记/" rel="next" title="laravel 笔记">
                <i class="fa fa-chevron-left"></i> laravel 笔记
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/05/08/微信相关/" rel="prev" title="微信相关">
                微信相关 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
          <div class="comments" id="comments">
             <div id="gitment-container"></div>
         </div>
  




        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">苏生不惑</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">382</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/sushengbuhuo" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="mysusheng@gmail.com" target="_blank" title="E-Mail">
                      
                        <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                  </span>
                
                  <span class="links-of-author-item">
                    <a href="https://plus.google.com/mysusheng" target="_blank" title="Google">
                      
                        <i class="fa fa-fw fa-google"></i>Google</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="http://v2ex.com/" title="v2ex" target="_blank">v2ex</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.fanhaobai.com/" title="fanhaobai" target="_blank">fanhaobai</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="yuanxuxu" target="_blank">yuanxuxu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.snail-c.cn/article" title="snail-c" target="_blank">snail-c</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://showcj.com/archives" title="showcj" target="_blank">showcj</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://vultr.aicnm.com/%E6%9C%80%E6%96%B0Vultr%E6%B3%A8%E5%86%8C%E5%8F%8AVPS%E8%B4%AD%E4%B9%B0%E5%9B%BE%E6%96%87%E6%95%99%E7%A8%8B/" title="vultr" target="_blank">vultr</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lucissfer.com/" title="lucissfer" target="_blank">lucissfer</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.csdn.net/fdipzone/article/details/79352685" title="傲雪星枫" target="_blank">傲雪星枫</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yoby123.cn/index.php/category/default/" title="小白的分享" target="_blank">小白的分享</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/p/5819995.html" title="PHP攻城狮" target="_blank">PHP攻城狮</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://blog.jiaojie.site/" title="php" target="_blank">php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://sphard.com/archives/" title="sphard" target="_blank">sphard</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://yuanxuxu.com/archives/" title="LNMP技术栈笔记" target="_blank">LNMP技术栈笔记</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.coding10.com/" title="学习 Laravel" target="_blank">学习 Laravel</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://shuwoom.com/?page_id=929" title="区块链学习指南" target="_blank">区块链学习指南</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://greenlightt.github.io/archives/" title="greenlightt" target="_blank">greenlightt</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.0php.net/archives/" title="0php" target="_blank">0php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.fordba.com/category/mysql" title="mysql" target="_blank">mysql</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.itcodemonkey.com/" title="程序员" target="_blank">程序员</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.yanshuo.me/r/v2ex" title="言说" target="_blank">言说</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.timiguo.com/archive.html" title="提米果的博客" target="_blank">提米果的博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://phpartisan.cn/news/112.html" title="phpartisan" target="_blank">phpartisan</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.cnblogs.com/52fhy/" title="飞鸿影" target="_blank">飞鸿影</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.54php.cn/" title="54php" target="_blank">54php</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.lazyman.vip/" title="营销" target="_blank">营销</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.njphper.com/archives/" title="做人呢最重要的就是开心" target="_blank">做人呢最重要的就是开心</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.h57.pw/" title="php 初心者" target="_blank">php 初心者</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#磁盘空间不足"><span class="nav-number">1.</span> <span class="nav-text">磁盘空间不足</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-push-报错-fatal-HttpRequestException-encountered"><span class="nav-number">2.</span> <span class="nav-text">git push 报错 fatal: HttpRequestException encountered.</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pip-install-失败"><span class="nav-number">3.</span> <span class="nav-text">pip install 失败</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#awk"><span class="nav-number">4.</span> <span class="nav-text">awk</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#批量删除-DS-Store-文件"><span class="nav-number">5.</span> <span class="nav-text">批量删除 .DS_Store 文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看硬盘及内存空间"><span class="nav-number">6.</span> <span class="nav-text">查看硬盘及内存空间</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#统计文件或目录的个数"><span class="nav-number">7.</span> <span class="nav-text">统计文件或目录的个数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看CPU和内存占用"><span class="nav-number">8.</span> <span class="nav-text">查看CPU和内存占用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#curl"><span class="nav-number">9.</span> <span class="nav-text">curl</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#连接你服务器-top10-用户端的-IP-地址"><span class="nav-number">10.</span> <span class="nav-text">连接你服务器 top10 用户端的 IP 地址</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#最常用的10个命令"><span class="nav-number">11.</span> <span class="nav-text">最常用的10个命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#alias"><span class="nav-number">12.</span> <span class="nav-text">alias</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#wget"><span class="nav-number">13.</span> <span class="nav-text">wget</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#防火墙"><span class="nav-number">14.</span> <span class="nav-text">防火墙</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#显示-Path-环境变量"><span class="nav-number">15.</span> <span class="nav-text">显示 Path 环境变量</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#判断字符串包含"><span class="nav-number">16.</span> <span class="nav-text">判断字符串包含</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#快速修改后缀名字"><span class="nav-number">17.</span> <span class="nav-text">快速修改后缀名字</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#数值排序"><span class="nav-number">18.</span> <span class="nav-text">数值排序</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#清理httpd服务日志超过3天的内容"><span class="nav-number">19.</span> <span class="nav-text">清理httpd服务日志超过3天的内容</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#awk获取json"><span class="nav-number">20.</span> <span class="nav-text">awk获取json</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#cpu"><span class="nav-number">21.</span> <span class="nav-text">cpu</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查看系统负载"><span class="nav-number">22.</span> <span class="nav-text">查看系统负载</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#秘钥登录"><span class="nav-number">23.</span> <span class="nav-text">秘钥登录</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#生成二维码"><span class="nav-number">24.</span> <span class="nav-text">生成二维码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#es-Kibana"><span class="nav-number">25.</span> <span class="nav-text">es Kibana</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#随机数生成"><span class="nav-number">26.</span> <span class="nav-text">随机数生成</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Elasticsearch-在-docker-和-CentOS-下的安装教程"><span class="nav-number">27.</span> <span class="nav-text">Elasticsearch 在 docker 和 CentOS 下的安装教程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#wget-命令提示-“use-‘–no-check-certificate"><span class="nav-number">28.</span> <span class="nav-text">wget 命令提示 “use ‘–no-check-certificate</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker"><span class="nav-number">29.</span> <span class="nav-text">docker</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#xargs-命令"><span class="nav-number">30.</span> <span class="nav-text">xargs 命令</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#禁用-eval-函数"><span class="nav-number">31.</span> <span class="nav-text">禁用 eval 函数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#find-模拟-tree"><span class="nav-number">32.</span> <span class="nav-text">find 模拟 tree</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Shell-命令组合"><span class="nav-number">33.</span> <span class="nav-text">Shell 命令组合</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Crontab-定时任务执行时的环境变量问题"><span class="nav-number">34.</span> <span class="nav-text">Crontab 定时任务执行时的环境变量问题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#终端技巧大集合"><span class="nav-number">35.</span> <span class="nav-text">终端技巧大集合</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#网络知识之-IP-与子网掩码"><span class="nav-number">36.</span> <span class="nav-text">网络知识之 IP 与子网掩码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ssh免密登录漏洞"><span class="nav-number">37.</span> <span class="nav-text">ssh免密登录漏洞</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#crontab-指定用户"><span class="nav-number">38.</span> <span class="nav-text">crontab 指定用户</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#gt-gt-gt"><span class="nav-number">39.</span> <span class="nav-text">&gt;  &gt;&gt;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#内网穿透"><span class="nav-number">40.</span> <span class="nav-text">内网穿透</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ab-压力测试"><span class="nav-number">41.</span> <span class="nav-text">ab 压力测试</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#https-证书注册工具"><span class="nav-number">42.</span> <span class="nav-text">https 证书注册工具</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#linux卡顿怎么排查"><span class="nav-number">43.</span> <span class="nav-text">linux卡顿怎么排查</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-1"><span class="nav-number">44.</span> <span class="nav-text">docker</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#cURL-error-28-Resolving-timed-out-after-5515-milliseconds"><span class="nav-number">45.</span> <span class="nav-text">cURL error 28: Resolving timed out after 5515 milliseconds</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#内存消耗最大的进程"><span class="nav-number">46.</span> <span class="nav-text">内存消耗最大的进程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx-负载均衡"><span class="nav-number">47.</span> <span class="nav-text">Nginx 负载均衡</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Nginx-配置常用参数"><span class="nav-number">48.</span> <span class="nav-text">Nginx 配置常用参数</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#反向代理后如何获取真实客户端-IP"><span class="nav-number">49.</span> <span class="nav-text">反向代理后如何获取真实客户端 IP</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#docker-入门"><span class="nav-number">50.</span> <span class="nav-text">docker 入门</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#忽略文件"><span class="nav-number">51.</span> <span class="nav-text">忽略文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#crontab-截断"><span class="nav-number">52.</span> <span class="nav-text">crontab %截断</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#查出访问量TOP10的IP"><span class="nav-number">53.</span> <span class="nav-text">查出访问量TOP10的IP</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#phpmyadmin-管理多台-MySQL"><span class="nav-number">54.</span> <span class="nav-text">phpmyadmin 管理多台 MySQL</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#pull-request流程"><span class="nav-number">55.</span> <span class="nav-text">pull request流程</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SSH-也通过-SS-代理"><span class="nav-number">56.</span> <span class="nav-text">SSH 也通过 SS 代理</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Github-关键字进行搜索"><span class="nav-number">57.</span> <span class="nav-text">Github 关键字进行搜索</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Bash-单命令行解释"><span class="nav-number">58.</span> <span class="nav-text">Bash 单命令行解释</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列出目录下所有被-git-忽略的文件"><span class="nav-number">59.</span> <span class="nav-text">列出目录下所有被 git 忽略的文件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#SSH-闲置时间过长而断开"><span class="nav-number">60.</span> <span class="nav-text">SSH 闲置时间过长而断开</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#安装-swoole-laravelS"><span class="nav-number">61.</span> <span class="nav-text">安装 swoole laravelS</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#error-src-refspec-matches-more-than-one"><span class="nav-number">62.</span> <span class="nav-text">error src refspec matches more than one</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ssh-连接-实现免密码登陆"><span class="nav-number">63.</span> <span class="nav-text">ssh 连接 实现免密码登陆</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#CentOS-部署-Laravel-应用"><span class="nav-number">64.</span> <span class="nav-text">CentOS 部署 Laravel 应用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Docker-Contos-搭建-PHP-环境"><span class="nav-number">65.</span> <span class="nav-text">Docker Contos 搭建 PHP 环境</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#git-笔记"><span class="nav-number">66.</span> <span class="nav-text">git 笔记</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#Shell-变量高级用法"><span class="nav-number">67.</span> <span class="nav-text">Shell-变量高级用法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#删除文件占用空间"><span class="nav-number">68.</span> <span class="nav-text">删除文件占用空间</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

<div class="copyright">&copy; <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">苏生不惑</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>



<div>
<span id="showDays"></span>

</div>

<span id="busuanzi_container_site_pv">
   总访问量:<span id="busuanzi_value_site_pv"></span>次
</span>



  <span class="post-meta-divider">|</span>



<div class="theme-info">
  <div class="powered-by"></div>
  <span class="post-count">博客全站共773.8k字</span>
</div>
<script>
var birthDay = new Date("11/20/2018");
var now = new Date();
var duration = now.getTime() - birthDay.getTime();
var total= Math.floor(duration / (1000 * 60 * 60 * 24));
document.getElementById("showDays").innerHTML = "本站已运行 "+total+" 天";
</script>

        
<div class="busuanzi-count">
  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv">
      <i class="fa fa-user"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_uv"></span>
      人次
    </span>
  

  
    <span class="site-pv">
      <i class="fa fa-eye"></i>
      <span class="busuanzi-value" id="busuanzi_value_site_pv"></span>
      次
    </span>
  
</div>








        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  











<script type="text/javascript">
    (function() {
        // 匿名函数，防止污染全局变量
        var utterances = document.createElement('script');
        utterances.type = 'text/javascript';
        utterances.async = true;
        utterances.setAttribute('issue-term','0')
        utterances.setAttribute('theme','')
        utterances.setAttribute('repo','sushengbuhuo/laravel_ioc_demo')
        utterances.crossorigin = 'anonymous';
        utterances.src = 'https://utteranc.es/client.js';
        // content 是要插入评论的地方
        document.getElementById('gitment-container').appendChild(utterances);
    })();
</script>


  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

  
<script>
  ((window.gitter = {}).chat = {}).options = {
    //room替换成自己的聊天室名称即可，room的名称规则是：username/roomname
    room: 'sushengbuhuo-chat/mychat'
  };
</script>
<script src="https://sidecar.gitter.im/dist/sidecar.v1.js" async defer></script>

</body>
</html>
